Need help converting shell VB to real VB
Can somebody help me convert this shell script to a normal script?
Set objShell=CreateObject("Wscript.Shell")
objShell.Run "Xcopy \\server\servershare\vpn403i\client\*.* c:\apps21\vpn403i\"
Set objApp = CreateObject("WScript.Shell")
objApp.Run "cmd /C C:\apps21\vpn403i\setup /s"
Thank you very much.
Set objShell=CreateObject("Wscript.Shell")
objShell.Run "Xcopy \\server\servershare\vpn403i\client\*.* c:\apps21\vpn403i\"
Set objApp = CreateObject("WScript.Shell")
objApp.Run "cmd /C C:\apps21\vpn403i\setup /s"
Thank you very much.
0 Comments
[ + ] Show comments
Answers (8)
Please log in to answer
Posted by:
anonymous_9363
16 years ago
What do you mean, convert it to a 'normal' script? It's looks perfectly normal to me, apart from the unnecessary creation of a second shell object [ Set objApp = CreateObject("WScript.Shell") ]
As ever, you may want to add error-trapping, e.g. ensuring that the directory tree 'c:\apps21\vpn403i' exists before proceeding. Always program/script defensively - assume nothing!
Set objShell=CreateObject("Wscript.Shell")
objShell.Run "Xcopy \\server\servershare\vpn403i\client\*.* c:\apps21\vpn403i\"
objShell.Run "cmd /C C:\apps21\vpn403i\setup /s"
As ever, you may want to add error-trapping, e.g. ensuring that the directory tree 'c:\apps21\vpn403i' exists before proceeding. Always program/script defensively - assume nothing!
Posted by:
anonymous_9363
16 years ago
Posted by:
case2k5
16 years ago
The script I posted works but one of my colleagues mentioned that if I call out a shell and try to deploy it with SMS, there might be problems since its not running under a user context.
I guess he wanted to stay with wmi scripting inside VBScript. Is there a better way to write this script for SMS? Also, sometimes when I run the script, it doesn't do the setup /s just the xcopy.
This is what the SMS engineer had started writing but it didn't work but I think he wants to use just the copyfolder command:
'On Error Resume NExt
Dim objShell, objNewPort, objWMIService, oFSO, Path, strComputerA
Dim RunErrorToReturn, Results
Dim strComputer : strComputer = "."
Dim objNetwork : Set objNetwork = CreateObject("WScript.Network")
strComputerA = objNetwork.ComputerName
Set objWMIService = GetObject("winmgmts:"& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
ProgramFiles = objShell.ExpandEnvironmentStrings("%ProgramFiles%")
windir= objShell.ExpandEnvironmentStrings("%windir%")
temp = objShell.ExpandEnvironmentStrings("%temp%")
allusers=objShell.ExpandEnvironmentStrings("%AllUsersProfile%")
path= oFSO.GetParentFolderName(WScript.ScriptFullName)
'oFSO.CopyFolder "\\server\servershare\VPN403i\client", "c:\apps21\vpn403i\" ,True
'objShell.Run path+"\apps21\vpn403i\setup /s",1,TRUE
Const FOF_CREATEPROGRESSDLG = &H0&
ParentFolder = Path
wscript.echo parentfolder
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(ParentFolder)
objFolder.CopyHere "C:\apps21\vpn403i", FOF_CREATEPROGRESSDLG
I guess he wanted to stay with wmi scripting inside VBScript. Is there a better way to write this script for SMS? Also, sometimes when I run the script, it doesn't do the setup /s just the xcopy.
This is what the SMS engineer had started writing but it didn't work but I think he wants to use just the copyfolder command:
'On Error Resume NExt
Dim objShell, objNewPort, objWMIService, oFSO, Path, strComputerA
Dim RunErrorToReturn, Results
Dim strComputer : strComputer = "."
Dim objNetwork : Set objNetwork = CreateObject("WScript.Network")
strComputerA = objNetwork.ComputerName
Set objWMIService = GetObject("winmgmts:"& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
ProgramFiles = objShell.ExpandEnvironmentStrings("%ProgramFiles%")
windir= objShell.ExpandEnvironmentStrings("%windir%")
temp = objShell.ExpandEnvironmentStrings("%temp%")
allusers=objShell.ExpandEnvironmentStrings("%AllUsersProfile%")
path= oFSO.GetParentFolderName(WScript.ScriptFullName)
'oFSO.CopyFolder "\\server\servershare\VPN403i\client", "c:\apps21\vpn403i\" ,True
'objShell.Run path+"\apps21\vpn403i\setup /s",1,TRUE
Const FOF_CREATEPROGRESSDLG = &H0&
ParentFolder = Path
wscript.echo parentfolder
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(ParentFolder)
objFolder.CopyHere "C:\apps21\vpn403i", FOF_CREATEPROGRESSDLG
Posted by:
anonymous_9363
16 years ago
ORIGINAL: case2k5What we in the UK might refer to as "utter tommy rot." I can't see any reason for that assertion, given what your script's doing.
one of my colleagues mentioned that if I call out a shell and try to deploy it with SMS, there might be problems since its not running under a user context.
As for error-trapping, my scripts would look something like this (note the use of the CODE tag - use the '%>' button):
On Error Resume Next
Set objShell=CreateObject("Wscript.Shell")
If Not IsObject(objShell) Then
WScript.Quit
End If
Set objFSO=CreateObject("Scripting.FileSystemObject")
If Not IsObject(objFSO) Then
WScript.Quit
End If
'// The paths could usefully be set with variables to save re-typing.
objShell.Run "Xcopy \\server\servershare\vpn403i\client\*.* c:\apps21\vpn403i\"
If objFSO.FolderExists("c:\apps21\vpn403i") Then
If objFSO.FileExists("c:\apps21\vpn403i\setup.exe") Then
objShell.Run "cmd /C C:\apps21\vpn403i\setup /s"
End If
End If
I think you get the idea which is, essentially, ASSUME NOTHING. Just because creating the shell object always works on your machine (and every machine you tested the script on) doesn't mean it'll work on every machine. As to not running the setup executable, I think that'll be because the XCOPY hasn't completed. I'll leave that as an exercise for you to work out. Here's a hint http://www.devguru.com/technologies/wsh/17419.asp
Posted by:
case2k5
16 years ago
It works after I modified the script like this:
On Error Resume Next
Set objShell=CreateObject("Wscript.Shell")
If Not IsObject(objShell) Then
WScript.Quit
End If
Set objFSO=CreateObject("Scripting.FileSystemObject")
If Not IsObject(objFSO) Then
WScript.Quit
End If
'// The paths could usefully be set with variables to save re-typing.
objShell.Run "Xcopy \\server\servershare\vpn403i\client\*.* c:\apps21\vpn403i\",1,TRUE
If objFSO.FolderExists("c:\apps21\vpn403i") Then
If objFSO.FileExists("c:\apps21\vpn403i\setup.exe") Then
objShell.Run "cmd /C C:\apps21\vpn403i\setup /s",1,TRUE
End If
End If
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.