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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbs as startup scipt - run exe as background process?

Status
Not open for further replies.

sjp770

IS-IT--Management
Apr 10, 2012
4
AU
I am looking for a method to call either an EXE or a bat file at startup (in a domain environment as a GPO startup script) and have it run in the background with admin rights (granted during startup script already).

The problem I have is that I call ccmsetup.exe and it runs ok. If the pc is way out of date ccmsetup will download any pre reqs which could take quite a while.

Is there a way to run the exe so it doesnt get terminated before a user logs in? at the moment it runs for a minute or so and then is terminated so that ctrl alt del can pop up.

I also have a bat script with a similar issue. Not sure about the bat script, but the exe GPO is set to wait for 3200 sec for login scripts to finish, so logically it should fail like this.


Maybe it's as simple as a start wait type command.. But I would rather let users continue to use the pc.
 
see if this helps

Function Jet
Set oExec = WshShell.Exec(("\\location\Jet35sp3.exe /Q"))
' wait until finished
Do While oExec.Status <> 1
WScript.Sleep 100
Loop
End Function

MCITP:EA/SA, MCSE, MCSA, MCDBA, MCTS, MCP+I, MCP
 
Hi !
Code:
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("calc")
Do While oExec.Status = 0
     WScript.Sleep 100
Loop
WScript.Echo oExec.Status
 
The .ExitCode property returns the exit code set by the program (calc.exe) when it exits.
Code:
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("calc")
Do While oExec.Status = 0
     WScript.Sleep 100
Loop
WScript.Echo "The Status code is " & oExec.Status
WScript.Echo "The ProcessID is : " & oExec.ProcessID
WScript.Echo "The ExitCode is : " & oExec.ExitCode
 
this is the current method, but it fails with an error about using () when called in this manner?

<code>
Const DestinationFile = "c:\windows\ccmsetup\ccmsetup.exe"
Const SourceFile = "\\****\*****\ccmsetup\ccmsetup.exe"
dim objShell

Set fso = CreateObject("Scripting.FileSystemObject")
Set objShell = WScript.CreateObject("WScript.Shell")
'Check to see if the file already exists in the destination folder
If Not fso.FileExists(DestinationFile) Then
'The file does not exist in the destination folder. Safe to copy file to this folder.
fso.CreateFolder("c:\windows\ccmsetup")
fso.CopyFile SourceFile, "c:\windows\ccmsetup\", True
End If
objShell.Run(DestinationFile & " /logon /mp:sccmserver SMSSITECODE=*** DNSSUFFIX=****.*****", 0, true)
Set fso = Nothing
Set objShell = Nothing
</code>
 
I added

DNSSUFFIX=****.*****", 0, true)

in the hopes of getting it to wait and thats when it errors out. When it ends like

DNSSUFFIX=****.*****")

It doesn't error out, but it terminates as soon as the vbs finishes.
 
Use either
Call objShell.Run(DestinationFile & " /logon /mp:sccmserver SMSSITECODE=*** DNSSUFFIX=****.*****", 0, true)
or
objShell.Run DestinationFile & " /logon /mp:sccmserver SMSSITECODE=*** DNSSUFFIX=****.*****", 0, true

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Solution is as below:

Option explicit
dim objShell

CopyAFile "\\****\ccmsetup", "c:\windows\ccmsetup", "ccmsetup.exe"

‘Format for the above cmd is CopyAFile “FQDN SOURCEPATH (no ip’s) , DESTINATION PATH, FILENAME

Function CopyAFile( Byval strSourceFolder, Byval strTargetFolder, Byval strFileName)

Dim objFSO, booOverWrite, strResult

Set objFSO = CreateObject( "Scripting.FileSystemObject")
If objFSO.FileExists( strSourceFolder & "\" & strFileName) _
And UCase( strSourceFolder) <> UCase( strTargetFolder) Then
If objFSO.FolderExists( strTargetFolder) Then
Else
objFSO.CreateFolder(strTargetFolder)
End If
If objFSO.FileExists( strTargetFolder & "\" & strFileName) Then
booOverWrite = vbTrue
Else
booOverWrite = vbFalse
End If
objFSO.CopyFile strSourceFolder & "\" & strFileName, strTargetFolder & "\", booOverWrite
End If


End Function

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "c:\windows\ccmsetup\ccmsetup.exe /logon /mp:****.****.*** SMSSITECODE=*** DNSSUFFIX=****", 0, true


Thanks to PHV for the no () idea, i thought it wouldn't work so i never tried it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top