• 0

vbscript to run audio file at startup


Question

Hey guys,

It has been requested to me that I setup something that will make it so that when a specific user logs in on any machine (this portion will be controlled by group policy), a specified audio file will play. This audio file will be played via network path. Unfortunately, I don't know anything about creating a batch file to do the job, and I know even less about VB. I just know how to make it so that it only works for this one user.

Any ideas?

7 answers to this question

Recommended Posts

  • 0

You could try this script, you will need to make a text file of the users.

This is the text file the script is looking for, you can have a full path to it

Notes

  Quote
 Dim Txt   : Txt = ("UserLists.txt")

Change this, as the script sits the Act.Run is comment out

  Quote
	  '/--->Place The Path To The File Here
	  'Act.Run("PATH_TO_THE_FILE"),1,False

To this now the Act.Run is active

  Quote
	  '/--->Place The Path To The File Here
	  Act.Run("PATH_TO_THE_FILE"),1,False

Now this script is only good for 1 person who logs in I have not

added any multi user checks.

Save As UserLogonPlayMusic.vbs

  Quote
Const ForReading=1
 Dim Act   : Set Act = CreateObject("Wscript.Shell")
 Dim Fso   : Set Fso = CreateObject("Scripting.FileSystemObject")
 Dim Txt   : Txt = ("UserLists.txt")
 Dim UName : UName = Act.ExpandEnvironmentStrings("%UserName%")
 Dim TS, StrU
  Set TS = Fso.OpenTextFile(TXT, ForReading)
	Do Until TS.AtEndOfStream
	 StrU = TS.ReadLine
	 If InStr(StrU, UName) Then 
	  '/--->Place The Path To The File Here
	  'Act.Run("PATH_TO_THE_FILE"),1,False 
	Loop
  TS.Close

If you wanted a multiuser it may look something like this.

This script does not need a text file

  Quote
 Dim Act   : Set Act = CreateObject("Wscript.Shell")
 Dim Fso   : Set Fso = CreateObject("Scripting.FileSystemObject")
 Dim UName : UName = Act.ExpandEnvironmentStrings("%UserName%")

	If InStr(UName, Al)  Or InStr(UName, Bob ) Or InStr(UName, Cathy) Then 
	  '/--->Place The Path To The File Here
	  'Act.Run("PATH_TO_THE_FILE_01"),1,False 
	 If InStr(UName, Doug)  Or InStr(UName, Eddie) Or InStr(UName, Fred) Then 
	  '/--->Place The Path To The File Here
	  'Act.Run("PATH_TO_THE_FILE_02"),1,False
	 If InStr(UName, Gordon)  Or InStr(UName,Hank) Or InStr(UName, Isable) Then 
	  '/--->Place The Path To The File Here
	  'Act.Run("PATH_TO_THE_FILE_03"),1,False
  • 0
  jake1eye said:

You could try this script, you will need to make a text file of the users.

This is the text file the script is looking for, you can have a full path to it

Notes

Change this, as the script sits the Act.Run is comment out

To this now the Act.Run is active

Now this script is only good for 1 person who logs in I have not

added any multi user checks.

Save As UserLogonPlayMusic.vbs

If you wanted a multiuser it may look something like this.

This script does not need a text file

To make the users list, is each username seperated by just pressing enter, or a special character? I am only doing this for one user...

Also, in the script, what would the path look like to the userslist, and where would it go?

  • 0

Ok, I created the users.txt file, and I created the script. I also created the GPO, and assigned it under User Properties > Logon Script. I applied it to my test OU where my test user sits. Right now I have it to the point where WMP opens up, is open for a short while, then closes. It doesn't play anything. I've moved my audio file to a more accessible location, however that did not help. Here is the script I created, however I am blocking out the server name & domain name.

Const ForReading=1
Dim Act   : Set Act = CreateObject("Wscript.Shell")
Dim Fso   : Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Txt   : Txt = ("\\**SERVER**\sysvol\**DOMAIN**\scripts\users.txt")
Dim UName : UName = Act.ExpandEnvironmentStrings("%UserName%")
Dim TS, StrU
  Set TS = Fso.OpenTextFile(TXT, ForReading)
	Do Until TS.AtEndOfStream
	 StrU = TS.ReadLine
	 If InStr(StrU, UName) Then
	  '/--->Place The Path To The File Here
	  Act.Run("\\**SERVER**\home\call_to_arms.wav"),1,False	Loop
  TS.Close

  • 0
  Punkrulz said:

Ok, I created the users.txt file, and I created the script. I also created the GPO, and assigned it under User Properties > Logon Script. I applied it to my test OU where my test user sits. Right now I have it to the point where WMP opens up, is open for a short while, then closes. It doesn't play anything. I've moved my audio file to a more accessible location, however that did not help. Here is the script I created, however I am blocking out the server name & domain name.

Const ForReading=1
Dim Act   : Set Act = CreateObject("Wscript.Shell")
Dim Fso   : Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Txt   : Txt = ("\\**SERVER**\sysvol\**DOMAIN**\scripts\users.txt")
Dim UName : UName = Act.ExpandEnvironmentStrings("%UserName%")
Dim TS, StrU
  Set TS = Fso.OpenTextFile(TXT, ForReading)
	Do Until TS.AtEndOfStream
	 StrU = TS.ReadLine
	 If InStr(StrU, UName) Then
	  '/--->Place The Path To The File Here
	  Act.Run("\\**SERVER**\home\call_to_arms.wav"),1,False	Loop
  TS.Close

Try to change this line

  Quote
Act.Run("\\**SERVER**\home\call_to_arms.wav"),1,False

To this

  Quote
Act.Run("wmplayer.exeSERVER**\home\call_to_arms.wav"),1,False

Or use this to play the wave file this will open faster then WMP

  Quote
Act.Run("sndrec32.exeSERVER**\home\call_to_arms.wav"),1,False
  • 0
  jake1eye said:

Try to change this line

To this

Or use this to play the wave file this will open faster then WMP

I definitely prefer sound recorder over WMP, for it's speed to open as well as the fact that if WMP 10 isn't configured, the configuaration box will come up first for the user instead of just playing.

HOWEVER: Same problem. :( Sound Recorder opens up very quickly, and then closes again, without playing the song!

Edit: On that same line that opens up the wave file, I changed the word 'false' to 'true'. Now when I login, Sound Recorder Opens with the file open, but it doesn't play it automatically. How can I get it to play automatically, and then close?

Edited by Punkrulz
  • 0

Change the Act.Run to this, you will have to add your path as this is what I tested it with.

This open sndrec32 plays the wav file then closes

  Quote
Act.Run("sndrec32y /close  H:\WINDOWS\Media\tada.wav"),1,True

Here is where I found the above informtion Hey, Scripting Guy!

  • 0

Thanks Jake, I think it's working now! There is only one unfortunate side effect, if I try to test it out on my computer, the windows sounds play, then the sound recorder opens up, but then immediately a popup comes up saying that there are no audio devices installed. I can see on my hard ware list that my SoundMAX Integrated Audio is installed, but Windows refuses to list that as a possible selection to use. Restarting my computer fixes that, but I haven't tried testing it again.

I have tried it on a machine in the back and that works fine. Unfortunately I don't know what makes it work and what makes it fail like it does on mine... but we'll have to see!

Thank you!

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I agree with open rights group that the age check companies should be regulated but action does need to be taken imo, they may be called irresponsible parents but the fact is that many don't know how to set up blocks. Why should kids suffer because their parents don't know something? I think the UK has always been a bit like this. We don't say healthcare is your responsibility, we tax everyone and make people register with the NHS. We also don't expect everyone to brush their teeth to maintain dental health, we just put fluoride in their water assuming people aren't brushing enough, because some probably aren't or aren't doing it properly. In general, this way of doing things works.
    • Well that's the weird thing, the UK really isn't a very religious country at all and the same politicians that are backing this (basically all of them) also support things like assisted dying which various religions spoke out against. I don't think this is coming from religion, of course religious groups will support it but I don't think they've started it.
    • No.  The only thing you'll be able to capture with that is via antenna (your local NBC, CBS, etc) or if you had a regular cable box you could capture ClearQAM channels (if they are still a thing...probably not though).  Everything else will have encryption which those capture cards aren't meant for.   So yeah...you'll need Verizon's DVR (sucks if you have to pay for it).
    • I've gotta say Microsoft has lost the plot a long, long, long time ago.
    • How is it be technically implemented, I mean if you wanted to include this let's say on this website, at what point do you interrupt the user flow and say yo! Show me your ID or get the hell out? Please go into extreme technical detail. Is it using a third-party, how much information does neowin receive from that third-party, at what point would that information be abused? We all know it would be abused. So hypothetically what would neowin receive from that third-party company?
  • Recent Achievements

    • One Month Later
      Falcon.ai earned a badge
      One Month Later
    • Week One Done
      Falcon.ai earned a badge
      Week One Done
    • Dedicated
      EYEREX earned a badge
      Dedicated
    • First Post
      Electronic Person earned a badge
      First Post
    • Week One Done
      CyberCeps666 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      628
    2. 2
      ATLien_0
      235
    3. 3
      Xenon
      164
    4. 4
      neufuse
      142
    5. 5
      +FloatingFatMan
      123
  • Tell a friend

    Love Neowin? Tell a friend!