Link to home
Start Free TrialLog in
Avatar of Thomas_Meyer
Thomas_MeyerFlag for Czechia

asked on

How to copy and run the file from the server using VB script?

Hi Experts,
I need help with simple vb script, which is responsible for:
 - Check whether one of two possible locations are set:
C:\Program Files (x86)\GIMP-2.0\bin\gimp-console-2.6.exe
 or
C:\Program Files\GIMP-2.0\bin\ gimp-console-2.6.exe
 If the script finds the file, and must be stopped. If the file is not found, so as to:

 - From the server, copy the executable file ("\\S3\i$\Gimp\gimp-June 2 11-i686-setup-1.exe") to a local temporary folder - ExpandEnvironmentStrings ("%Temp%")
 - Run the exe file copied using the command:
runas /user:mydomain@user /mypassword %TMP%\gimp-June 2 11-i686-setup-1.exe /VERYSILENT /SUPPRESSMSGBOXES /NORESTART

Open in new window

- Finally, after installing the script delete the exe file from the Windows temporary folder.

Thank you in advance for any help.
TM













Avatar of X Layer
X Layer
Flag of Slovenia image

Ok let's see if I understand. If "gimp-console-2.6.exe" process is running, must be stopped first?
Avatar of Thomas_Meyer

ASKER

No, the first requirement applies only checks whether the program is no longer the "GIMP" installed on the computer (verify the existence of a file in the specified locations). If the executable file exists either in "C:\Program Files\ ..." for 32-bit operating systems, or "C:\Program Files (x86)\ ..." for 64-bit operating systems, so the script must end. If these files do not exist the script should proceed to the second point - that is, copy the installation file.
Ok, try this script:
Dim objWSH, objFSO, x86Path, x64Path, SetupPath, TempPath

Set objWSH = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
x86Path = """C:\Program Files\GIMP-2.0\bin\gimp-console-2.6.exe"""
x64Path = """C:\Program Files (x86)\GIMP-2.0\bin\gimp-console-2.6.exe"""
SetupPath = """\\S3\i$\Gimp\gimp-June 2 11-i686-setup-1.exe"""
TempPath = objWSH.ExpandEnvironmentStrings(%temp%)

If objFSO.FileExists(x86Path) or objFSO.FileExists(x64Path) Then
	WScript.Quit
Else
	objFSO.CopyFile SetupPath, TempPath
	objWSH.Run  "cmd.exe /C runas /user:mydomain@user /mypassword " & TempPath &_
	"\gimp-June 2 11-i686-setup-1.exe /VERYSILENT /SUPPRESSMSGBOXES /NORESTART"

Open in new window

When you run the script, the script writes an error to 15 line, missing command 'End':


Dim objWSH, objFSO, x86Path, x64Path, SetupPath, TempPath

Set objWSH = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
x86Path = """C:\Program Files\GIMP-2.0\bin\gimp-console-2.6.exe"""
x64Path = """C:\Program Files (x86)\GIMP-2.0\bin\gimp-console-2.6.exe"""
SetupPath = """\\S3\i$\Gimp\gimp-June 2 11-i686-setup-1.exe"""
TempPath = objWSH.ExpandEnvironmentStrings("%temp%")

If objFSO.FileExists(x86Path) or objFSO.FileExists(x64Path) Then
      WScript.Quit
Else
      objFSO.CopyFile SetupPath, TempPath
      objWSH.Run  "cmd.exe /C runas /user:mydomain@user /mypassword " & TempPath &_
      "\gimp-June 2 11-i686-setup-1.exe /VERYSILENT /SUPPRESSMSGBOXES /NORESTART"
Ups, of course:
Dim objWSH, objFSO, x86Path, x64Path, SetupPath, TempPath

Set objWSH = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
x86Path = """C:\Program Files\GIMP-2.0\bin\gimp-console-2.6.exe"""
x64Path = """C:\Program Files (x86)\GIMP-2.0\bin\gimp-console-2.6.exe"""
SetupPath = """\\S3\i$\Gimp\gimp-June 2 11-i686-setup-1.exe"""
TempPath = objWSH.ExpandEnvironmentStrings(%temp%)

If objFSO.FileExists(x86Path) or objFSO.FileExists(x64Path) Then
        WScript.Quit
Else
        objFSO.CopyFile SetupPath, TempPath
        objWSH.Run  "cmd.exe /C runas /user:mydomain@user /mypassword " & TempPath &_
        "\gimp-June 2 11-i686-setup-1.exe /VERYSILENT /SUPPRESSMSGBOXES /NORESTART"
End If

Open in new window

Ok, but I still in the script meets on the last point of my entry:
after installation is complete, delete the installation file from the% TEMP%
The best way that I can think of is to verify the processes are running:
gimp-2.6.11-i686-setup-1.exe
and
gimp-2.6.11-i686-setup-1.tmp

As long as both processes are running, the script will not (can not) delete the installation files. It occurs to me at the end of the script to add a control loop that processes exist. If processes exist and are currently being created directory either "x86Path" or "x64Path", so must delete the installation file. Otherwise the script in a loop to wait. This is according to this assignment, please be done?
Thank you.
TM
ASKER CERTIFIED SOLUTION
Avatar of X Layer
X Layer
Flag of Slovenia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tighec
tighec

I know you asked for a vbscript but why not just use a simple batch file?

If EXIST "C:\Program Files (x86)\GIMP-2.0\bin\gimp-console-2.6.exe" GOTO :EOF
If EXIST "C:\Program Files\GIMP-2.0\bin\ gimp-console-2.6.exe" GOTO :EOF
Copy "\\S3\i$\Gimp\gimp-June 2 11-i686-setup-1.exe" %TMP% /Y
runas /user:mydomain@user /mypassword "%tmp%\gimp-June 2 11-i686-setup-1.exe" /VERYSILENT /SUPPRESSMSGBOXES /NORESTART
Thanks for the help
 TM