Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Startup Script Help..

Status
Not open for further replies.

MoleDirect

Technical User
Sep 4, 2007
45
US
Hello all.. I am looking to create a VBS file that can fire off a users log on script. I am looking to find out what process launches the windows start up script (to what is specified in Active directory) on their computer, because I want to call it from a script. Is anyone familiar with this one?


Thanks in advance!
 
This script will get the username, logonserver, and script path and then run the associated script. This assumes that it is a batch file not another vbs file.


-------------------

On Error Resume Next
strComputer = "."
Dim objNet
Set objNet = CreateObject("WScript.NetWork")
strUserName = objNet.UserDomain & "\" & objNet.UserName
'WScript.Echo strUserName

Set WshShell = WScript.CreateObject("WScript.Shell")
Set objShell = CreateObject("Wscript.Shell")
Set objEnv = objShell.Environment("process")
strServer = objEnv("LOGONSERVER")

Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
Set objTranslator = CreateObject("NameTranslate")
objTranslator.Init ADS_NAME_INITTYPE_GC, ""
objTranslator.Set ADS_NAME_TYPE_NT4, strUserName
strUserDN = objTranslator.Get(ADS_NAME_TYPE_1779)

Set objItem = GetObject("LDAP://" & strUserDN)

strscriptPath = objItem.Get("scriptPath")

Dim LogonScript
LogonScript = strServer & "\netlogon\" & strscriptPath
WScript.Echo LogonScript
return = WshShell.Run("cmd /c """ & LogonScript & """")
'WScript.Echo return

----------------


 
OOPS!!

change the last block of code to look like this..

Dim LogonScript
LogonScript = strServer & "\netlogon\" & strscriptPath
'WScript.Echo LogonScript
return = WshShell.Run("cmd /c """ & LogonScript & """")
'WScript.Echo return
 
EXCELENT!!!

This is what I am looking for!!

I will combine this, to another script which should be fired off the VPN client..

What I am hoping it will do is run quietly, once a user tries to connect to the VPN. It will check every 5 seconds for a full minute for the IP to change to 10.n.n.n and when it does, it will fire off the script. After one minute, it will fail quietly..

I am fairly new to vbs, but this is a HUGE step.. THANK YOU!!!!!!

 
It looks like it is able to detect the LogonScript, but it wont run it... I have tried several methods.. here is where I am so far.

Code:
'On Error Resume Next
strComputer = "."
    Dim objNet,runme,x
    Set objNet = CreateObject("WScript.NetWork")
    strUserName = objNet.UserDomain & "\" & objNet.UserName
    'WScript.Echo strUserName
    
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set objShell = CreateObject("Wscript.Shell")
    Set objEnv = objShell.Environment("process")
    strServer = objEnv("LOGONSERVER")

Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
    Set objTranslator = CreateObject("NameTranslate")
    objTranslator.Init ADS_NAME_INITTYPE_GC, ""
    objTranslator.Set ADS_NAME_TYPE_NT4, strUserName
    strUserDN = objTranslator.Get(ADS_NAME_TYPE_1779)
 
Set objItem = GetObject("LDAP://" & strUserDN)
 
strscriptPath = objItem.Get("scriptPath")

Dim LogonScript
LogonScript = strServer & "\netlogon\" & strscriptPath
	'WScript.Echo LogonScript
WScript.Sleep 100
	'return = WshShell.Run("cmd /k " & LogonScript)
	'MSGBOX("cmd /k " & LogonScript)
	'WScript.Echo return 
msgbox(LogonScript)
x = ("rundll32 url.dll,FileProtocolHandler " & LogonScript)
WshShell.run x

Let me know if you have any ideas for this one.

Thanks!!
 
what are you trying to acomplish with this line?
rundll32 url.dll,FileProtocolHandler

The script runs the logon script the way it was posted, so I am not sure what that line is supposed to do for you...
 
For some reason, the script would'nt run the otherway. It brought up a DOS windo and closed it right away. This was a method I used to open any filetype without having to specify what executable runs it.
 
the line
("cmd /c """ & LogonScript & """")
tells it to open the cmd window run the command LogonScript and close. The /c tells it to close the window. If you remove the /c from the line, it should leave the window open.

Make sure that all the quotes are there...

here is the full script again without the /c try that.



--------

On Error Resume Next
strComputer = "."
Dim objNet
Set objNet = CreateObject("WScript.NetWork")
strUserName = objNet.UserDomain & "\" & objNet.UserName
'WScript.Echo strUserName

Set WshShell = WScript.CreateObject("WScript.Shell")
Set objShell = CreateObject("Wscript.Shell")
Set objEnv = objShell.Environment("process")
strServer = objEnv("LOGONSERVER")

Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
Set objTranslator = CreateObject("NameTranslate")
objTranslator.Init ADS_NAME_INITTYPE_GC, ""
objTranslator.Set ADS_NAME_TYPE_NT4, strUserName
strUserDN = objTranslator.Get(ADS_NAME_TYPE_1779)

Set objItem = GetObject("LDAP://" & strUserDN)

strscriptPath = objItem.Get("scriptPath")

Dim LogonScript
LogonScript = strServer & "\netlogon\" & strscriptPath
'WScript.Echo LogonScript
return = WshShell.Run("cmd """ & LogonScript & """")
'WScript.Echo return

-------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top