• 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?

Link to comment
Share on other sites

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

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

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

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

To this now the Act.Run is active

	  '/--->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

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 
	 End If 
	Loop
  TS.Close

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

This script does not need a text file

 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 
	 End If 
	 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 
	 End If
	 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 
	 End If
Link to comment
Share on other sites

  • 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

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?

Link to comment
Share on other sites

  • 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
	 End If
	Loop
  TS.Close

Link to comment
Share on other sites

  • 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
	 End If
	Loop
  TS.Close

Try to change this line

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

To this

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

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

Act.Run("sndrec32.exe \\**SERVER**\home\call_to_arms.wav"),1,False
Link to comment
Share on other sites

  • 0

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
Link to comment
Share on other sites

  • 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

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

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

Link to comment
Share on other sites

  • 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!

Link to comment
Share on other sites

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

    • No registered users viewing this page.