/build/static/layout/Breadcrumb_cap_w.png

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.

0 Comments   [ + ] Show comments

Answers (8)

Posted by: anonymous_9363 16 years ago
Red Belt
0
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") ]
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: AngelD 16 years ago
Red Belt
0
By real VB I guess he means Visual Basic and not VBScript
Posted by: anonymous_9363 16 years ago
Red Belt
0
...which then begs the question, which version of VB? 3? 5? 6? .Net?

As ever, our psychic powers are required! :)
Posted by: AngelD 16 years ago
Red Belt
0
I like the term "polish the crystal balls" better though [:D]
Posted by: case2k5 16 years ago
Orange Belt
0
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
Posted by: case2k5 16 years ago
Orange Belt
0
How do I add error trapping on that script VBScab?

thx
Posted by: anonymous_9363 16 years ago
Red Belt
0
ORIGINAL: case2k5
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.
What 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.

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
Orange Belt
0
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.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ