I'm currently working with an old script for a process that was in place before I took a look at it, the premise is to automatically create a folder and copy the contents of a flash drive into a C: drive. Below is the portion of the script I am concerned with:
xcopy "E:\directory" "c:\directory" /s /y
This is the script as I have it now, currently I need to change the first directory entry almost every time I plug into a new device as the drive letter as it appears in the script is sometimes different then what is on the local device. For example, the UBS drive would be D: on a laptop, but E: on most desktops, or some other letter in the case of a device with multiple peripherals.
Previously the script looked something like:
xcopy "...\directory" "c:\directory" /s /y
This doesn't function as the .bat file would come back with an inability to locate said directory on the UBS drive. When I manually change the .bat file to hard set the USB drive letter everything flows fine, all directories copy and the subsequent scripts run fine.
My question, any ideas on how to set the xcopy script to recognize the dynamic USB drive letter and allow for copying without having to change the script on each device?
Thanks!
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set evtDevice = objWMIService.ExecNotificationQuery ("SELECT * FROM Win32_VolumeChangeEvent")
Wscript.Echo "Waiting for events ..."
Do
Set objReceivedEvent = evtDevice.NextEvent
'report an event
Wscript.Echo " Win32_Device Changed event occurred" & VBNewLine
If objReceivedEvent.EventType = 1 Then
Wscript.Echo "Type = Config Changed"
ElseIf objReceivedEvent.EventType = 2 Then
Wscript.Echo "Type = Device Arrived"
Set colItems = objWMIService.ExecQuery("Select * From Win32_Volume")
For Each objItem in colItems
If objitem.DriveType = 2 then
Wscript.Echo objItem.DriveType & " " & objItem.Name & " " & objItem.driveletter
Set objShell = CreateObject("Shell.Application")
Set Ag=Wscript.Arguments
set WshShell = WScript.CreateObject("WScript.Shell")
Set SrcFldr=objShell.NameSpace(objitem.driveletter)
Set DestFldr=objShell.NameSpace("c:\test\")
Set FldrItems=SrcFldr.Items
DestFldr.CopyHere FldrItems, &H214
Wscript.Echo "Finished Copying"
Wscript.sleep 2000
End If
Next
ElseIf objReceivedEvent.EventType = 3 Then
Wscript.Echo "Type = Device Left"
ElseIf objReceivedEvent.EventType = 4 Then
Wscript.Echo "Type = Computer Docked"
End If
Loop
This vbs script waits for a USB to be inserted then copies it to a folder.
Remove all the debugging wscript.echo lines. Change the destination folder.
It copies all attached USB drives.
despite the previous answer from Noodles
#echo off
set "destDrive="
for /F "usebackq tokens=1,2 delims==" %i in (`"wmic logicaldisk get caption, drivetype"`) do (
if %%j EQU 2 set "destDrive=%%i"
)
if "%destDrive%" EQU "" (
echo No pendrive found
) else (
echo copying
xcopy "%destDrive%\directory\*.*" "c:\directory\*.*" /s /y
echo done...
)
Why not modify the batch file to ask for the drive letter before the copy begins?
SET /P USB=Enter USB Drive Letter (C:, D:, E: etc):
XCOPY "%USB%\directory" "C:\directory" /s /y
Related
i want to run a .wav-file. This is with
start "" SoundFile.wav
totally practical. But how can i run the window of the standard-windows-soundplayer minimized? So that nothing of my view changes?
start "" SoundFile.wav /MIN
start "" SoundFile.wav /min
start "" SoundFile.wav -MIN
start "" SoundFile.wav -min
didn't work sadly.
Can you help me?
Greets.
Sorry but i am not familiar with stackoverflow, so i can't make it that understandable, but i hope that this is enough.
In a simple way, you could just use a VBS like this:
s = createobject("WScript.Shell")
s.run "music.mp3", 2
Or create an automatic and CLI program to do this:
runmusic.bat
#echo off
set music=%1
set music=%music:"=%
if ":" neq "%music:~1,1%" set music=%cd%\%music%
if "%music:~-4%" neq ".mp3" set music=%music%.mp3
set katorn=%random%
echo >>"%temp%\%katorn%.vbs" set s = createobject("WScript.Shell")
echo >>"%temp%\%katorn%.vbs" s.run "%music%", 2
cscript "%temp%\%katorn%.vbs"
:: Uncomment the next line to autodelete the vbs file.
:: del /q /f "%temp%\%katorn%.vbs"
Usage:
runmusic (name or full path with quotation marks)
In a "professional way" you could do a shortcut file that starts the file minimized.
It could be useful if you needs the musics to have the "artist logo" or something like that, also if you don't want to use an CMD all the time...
Delete all comments to execute.
Set WshShell = CreateObject ("Wscript.Shell")
strDesktop = "X:\Shortcutlocation\yoo"
Set Shortcut = WshShell.CreateShortcut(strDesktop + "\MusicNameMaybe.lnk")
Shortcut.WindowStyle = "7"
Shortcut.IconLocation = "X:\IconPath\youricon.ico" // You can delete this and the file will be the same ever and forever.
Shortcut.TargetPath = "X:\yourpath\music.mp3"
Shortcut.Save
And you don't have to keep the shortcuts on the desktop if you don't want to, you don't even have to keep them fixed. Example:
runmusic.bat
#echo off
set music=%1
set music=%music:"=%
if ":" neq "%music:~1,1%" set music=%cd%\%music%
set music=%music%.mp3
set katorn=%random%
echo >>"%temp%\%katorn%.vbs" Set WshShell = CreateObject ("Wscript.Shell")
echo >>"%temp%\%katorn%.vbs" strDesktop = "%temp%"
echo >>"%temp%\%katorn%.vbs" Set Shortcut = WshShell.CreateShortcut(strDesktop + "\%katorn%.lnk")
echo >>"%temp%\%katorn%.vbs" Shortcut.WindowStyle = "7"
echo >>"%temp%\%katorn%.vbs" Shortcut.TargetPath = "%music%"
echo >>"%temp%\%katorn%.vbs" Shortcut.Save
cscript "%temp%\%katorn%.vbs"
:: Uncomment the next two lines to delete the temporary files.
:: del /q /f "%temp%\%katorn%.vbs"
:: del /q /f "%temp%\%katorn%.lnk"
echo Enjoy!
Usage:
runmusic (name or full path with quotation marks)
Now that you understand, you can even leave a folder with the songs and the other with just the customized shortcuts, which can come in handy.
Hope this helps,
K.
I'm currently making an installation script by using a .cmd file.
Here is my code:
IF EXIST "%USERPROFILE%\Desktop\Opslag\Opslag.hta" (
START "" "%USERPROFILE%\Desktop\Opslag\Opslag.lnk" /secondary /minimized
MSG "%USERNAME%" The program is already installed.
EXIT
) ELSE (
XCOPY %SOURCE% %DESTINATION% /D /E /C /R /I /K /Y
START "" "%USERPROFILE%\Desktop\Opslag\Opslag.lnk" /secondary /minimized
MSG "%USERNAME%" Setup is complete!
EXIT
)
The %SOURCE% and %DESTINATION% are set earlier in the script.
When the folder has been copied I want the file %USERPROFILE%\Desktop\Opslag\Opslag.lnk to be added to the Start Menu.
I have seen earlier posts like:
How to pin to start menu using PowerShell, but I cannot make it work.
I'm currently testing it on my home laptop which runs Windows 7 with danish language. The machine where I need to do this runs Windows 7 with english language. Therefore I think the $verb is different from the scripts I've found, but I haven't tested on my work station.
Furthermore my work station has a very limited UAC,
and therefore I do not have Administrator rights. And please do not comment on how this should not be done by users, but only Administrators/IT, as I know what I'm doing.
I hope someone can help me pin the Opslag.lnk to the Start Menu, preferably on both languages (danish and english).
Find the location of the Start Menu folder:
For /f "tokens=3*" %%G in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Start Menu" ^|Find "REG_"') do Call Set _startmenu=%%H
echo %_startmenu%
pause
In another search I stumbled across a very usefull VBScript: http://blogs.technet.com/b/deploymentguys/archive/2009/04/08/pin-items-to-the-start-menu-or-windows-7-taskbar-via-script.aspx:
Const CSIDL_COMMON_PROGRAMS = &H17
Const CSIDL_PROGRAMS = &H2
Set objShell = CreateObject("Shell.Application")
Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS)
strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path
Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Accessories")
Set objFolderItem = objFolder.ParseName("Calculator.lnk")
Set colVerbs = objFolderItem.Verbs
For Each objVerb in colVerbs
Wscript.Echo objVerb
Next
The script lists alle the verbs for the specifik program, in this case the Calculator. Unfortunately the verb "Pin to Start Menu" in my Opslag.lnk is not listed, and therefore I do not think this can be done with verbs. Hope some one else has other ideas.
I used a .vbs to do this in the current profile (and used the registry, runonce to launch the .vbs on all (new)userprofiles). We are working with both Dutch and English devices in our company so you will see that it will try both languages. The problem is that it did not work on a .lnk but you can always create an exe referring to your desired destination.
Dim strFolder, strExecutable
Set objShell = CreateObject("Shell.Application")
strFolder = "C:\Tools"
strExecutable = "Tool.exe"
Set objFolder = objShell.Namespace(strFolder)
Set objFolderItem = objFolder.ParseName(strExecutable)
Set colVerbs = objFolderItem.Verbs
'Loop through the verbs and if PIN is found then 'DoIt' (execute)
blnOptionFound = False
For Each objVerb In colVerbs
If Replace(objVerb.name, "&", "") = "Aan het menu Start vastmaken" Then
objVerb.DoIt
blnOptionFound = True
End If
Next
For Each objVerb In colVerbs
If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then
objVerb.DoIt
blnOptionFound = True
End If
Next
Please check what is wrong with the below code. I'm trying to zip the file of one folder and placing it in other folder. I have 94 files but out of that only 80 to 82 or like that some files are zipping. I am using a .bat file:
#setlocal
#echo off
set TIMESTAMP = %DATE:~4,2%-%DATE:~7,2%-%DATE:~10,4%
::CD C:\Desktop\Batchscripts\TESTZIP
::md C:\Desktop\Batchscripts\TESTZIP\%TIMESTAMP%
ECHO ------- BEGIN zip ----------------
CScript "C:\Desktop\Batchscripts\TESTZIP\zip.vbs" "C:\Desktop\Batchscripts\%TIMESTAMP%\" C:\Desktop\Batchscripts\TESTZIP\%TIMESTAMP%.zip
ECHO All production export xml files are completed. please find the location C:\Desktop\Batchscripts\TESTZIP\%TIMESTAMP%.zip
Pause
IF NOT %ERRORLEVEL% EQU 0 (goto :error)
ECHO ------- END zip------------------
which is calling a VBScript:
'Get command-line arguments.
Set objArgs = WScript.Arguments
InputFolder = objArgs(0)
ZipFile = objArgs(1)
'Create empty ZIP file.
CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
Set objShell = CreateObject("Shell.Application")
Set source = objShell.NameSpace(InputFolder).Items
objShell.NameSpace(ZipFile).CopyHere(source)
'Required!
wScript.Sleep 2000
Most likely your VBScript doesn't wait long enough. Try increasing the value to 5000 or 10000 milliseconds.
The Problem with the CopyHere method is that it runs asynchronously, i.e. it returns immediately instead of waiting until the operation is finished. However, the Shell.Application object is automatically destroyed when the script exits, thus terminating an ongoing CopyHere operation. If that operation wasn't completed at that point, your zip archive will be a couple files short.
This is my first question on here, because, although I have searched at least 15 different other posts for the answer to my issue, none have the answer. Please help!
QUESTION: How do I fix Error:800A0009?
DETAILS: I am creating a small program that gathers all local computers and sends them all an audio file to be played. Also, I need to know how to force send, if anyone knows. Lastly, I first run "Get Computers.bat".
My Code:
~~~~~~VBS FILE(Remote Speak.vbs)~~~~~~~~~~~~~~~~~~~
(Obtains variable transferred which contains network name of a computer, and sends it a file to be play using SAPI)
'get ip
Option Explicit
Dim args, strOut
set args = Wscript.arguments
strOut= args(0)
IP = strOut
'get MSG
MSG = InputBox("Type what you want the PC to say:", "Remote Voice Send By X BiLe", "")
If MSG = "" Then WScript.quit: Else
'vbs command to send
A = "on error resume next" & VBCRLF & _
"CreateObject(""SAPI.SpVoice"").speak " & """" & MSG & """" & VBCRLF & _
"CreateObject(""Scripting.FileSystemObject"").DeleteFile (""C:\Voice1.vbs"")"
' Create the vbs on remote C$
CreateObject("Scripting.FileSystemObject").OpenTextFile("\\" & ip & "\C$\Voice1.vbs",2,True).Write A
' Run the VBS through Wscript on remote machine via WMI Object Win32_Process
B = GetObject("winmgmts:\\" & IP & "\root\cimv2:Win32_Process").Create("C:\windows\system32\wscript.exe ""C:\Voice1.vbs""", null, null, intProcessID)
~~~BATCH PRIMARY (Get Computers.bat)~~~~~~~~~~~
(Gathers computer names and assign each one, using net view, filtering the "\" to Computer%num%. Also, :tempcall is just an error handler.)
#echo off
cls
set num=1
echo #echo off > Computers.bat
if "%1"=="loop" (
for /f "delims=\ tokens=*" %%a in ('net view ^| findstr /r "^\\\\"') do (
set comp=%%a
call :number
if exist %%f exit
)
goto :eof
)
cmd /v:on /q /d /c "%0 loop"
:tempcall
call temp.bat
echo.
echo.
echo.
echo You have %num%computers on your network!
pause>nul
del /q temp.bat
start Computers.bat
exit
:number
if %comp% == "" (
goto :tempcall
) else (
echo set Computer%num%=%comp% >> Computers.bat
echo cscript "Remote Speak.vbs" %1 >> Computers.bat
echo call "Remote Speak.vbs" >> Computers.bat
echo set num=%num% > temp.bat
echo Computer%num%: %comp%
set /a num=%num% + 1
)
BATCH SECONDARY (Computers.bat)
(The computers I made up off the top of my head, but they are generally in that format.)
#echo off
set Computer1=040227-CYCVN1
cscript "Remote Speak.vbs" //NoLogo > log.txt
set Computer1=051448-YZVN2
cscript "Remote Speak.vbs" //NoLogo > log.txt
pause>nul
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~END DETAILS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.) Temp.bat is literally just temporary, it's deleted, as you can see, almost immediately after it's created, it simply holds the value of %num% after it breaks out of the loop, because it didn't show "You have %num%computers on your network!" correctly.
2.) Don't worry too much about the VBScript file except for the top lines:
Option Explicit
Dim args, strOut
set args = Wscript.arguments
strOut= args(0)
IP = strOut
3.) My main issue is that I am trying to find a safe way to have "Computers.bat" call the "Remote Speak.vbs" file and set it's batch variables to be the exact same names to refer to the individual computers, in VBScript variable format.
The error raises because you are not passing any argument to the vbs file, and it is not passed because when you generate computers.bat you are using %1 (the first argument to the :number subroutine) as a parameter, but in call :number there is not any parameter.
Also, the incrementing computer number is not shown in computers.bat because delayedexpansion is not active. When execution reaches a line or block (the code inside parenthesis), the parser replaces variable reads with the value in the variable and then starts to execute it. As the value of the variable changes inside the block, but there is no variable read, only the value of the variable before starting to execute, changes are not seen. You need to setlocal enabledelayedexpansion to enable it and, where needed, change %var% to !var! to indicate the parser that the variable read needs to be delayed, not replaced at initial parse time.
And anyway, your code does not use it. And what is if exist %%f? And why the loop?
For your third question, the Environment property of the WshShell objects lets you read the required variables
Dim env
Set oEnvironment = WScript.CreateObject("WScript.Shell").Environment("PROCESS")
WScript.Echo oEnvironment("Computer1")
This is a fast cleanup of your code. From your question it seems this is only the starting point. Adapt as needed.
RemoteSpeak.vbs
Option Explicit
If WScript.Arguments.Count < 1 Then
WScript.Quit
End If
'get ip
Dim IP
IP = WScript.Arguments.Item(0)
'get MSG
Dim MSG
MSG = InputBox("Type what you want the PC to say:", "Remote Voice Send By X BiLe", "")
If MSG = "" Then
WScript.Quit
End If
Dim A
A = "on error resume next" & VBCRLF & _
"CreateObject(""SAPI.SpVoice"").speak " & """" & MSG & """" & VBCRLF & _
"CreateObject(""Scripting.FileSystemObject"").DeleteFile(WScript.ScriptFullName)"
' Create the vbs on remote C$
CreateObject("Scripting.FileSystemObject").OpenTextFile("\\" & IP & "\C$\Voice1.vbs",2,True).Write A
' Run the VBS through Wscript on remote machine via WMI Object Win32_Process
Dim B
B=GetObject("winmgmts:\\" & IP & "\root\cimv2:Win32_Process").Create("C:\windows\system32\wscript.exe ""C:\Voice1.vbs""", null, null, intProcessID)
getComputers.bat
#echo off
setlocal enableextensions enabledelayedexpansion
cls
set "num=0"
( echo #echo off
for /f "tokens=* delims=\" %%a in ('net view ^| findstr /r /c:"^\\\\"') do (
set /a "num+=1"
echo set "Computer!num!=%%a"
echo cscript "RemoteSpeak.vbs" %%a
)
) > computers.bat
echo You have %num% computers in your network
pause > nul
start Computers.bat
endlocal
exit /b
Dim env
Set oEnvironment = WScript.CreateObject("WScript.Shell").Environment("PROCESS")
WScript.Echo oEnvironment("Computer1")
I'm new to VBScript. I cannot find a way to copy files from one XP host to another using WMI in a VBS. The usual way of copying files (RPC - Remote Procedure Call, SMB, UNC) are not available to several hosts but WMI is available to all hosts, and I need to copy files from my admin host to a target Windows host. I thought I'd find some sample code out there but I've found no info on it. Haven't found anything telling me it can't be done, either.
The source files are an executable and 'test1.txt' in my admin computer's 'F:\TEMP' folder. I want to put the files on remote host HOST1's 'C:\TEMP' folder. I have full admin rights on both hosts. Here is what I have so far, just for one file (to keep the testing simple):
strComputer = "HOST1"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery( _
"Select * from Win32_Directory where Name = 'c:\\temp'")
For Each objFiles in colFiles
errResults = objFolder.Copy("f:\temp\test1.txt")
Wscript.Echo errResults
Next
I learned that WMI cannot create files on a remote host, and it cannot copy files over a network connection:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa389288%28v=vs.85%29.aspx
However, it can run a cmd process. Here's Frank White's code in C sharp, followed by his example:
https://stackoverflow.com/a/8913231/1569434
InputParameters("CommandLine") = "cmd /c echo myFTPCommands > c:\ftpscript.txt"
You will need four things to use all the following scriptlets, which build on each other to use psexec to run a "normal" VBScript or batch script on the remote host:
admin rights on the remote host;
WMI enabled on the remote host
a network share (using RPC, UNC, FTP, etc., but NOT DFS! ("Distributed File System" - see note) that your remote host can access; and
psexec.exe and your "normal" script(s) on the network share.
Important Note: Do NOT use DFS to map the network share! It will fail if you use Distributed File System for your network share. An error code you might get depending on how you try is "System error 1312", no matter which operating system (e.g., XP, Win 7) you use.
When RPC is not available on a remote host but WMI is, then the following method will create a local ASCII file on the remote host's c:\temp folder, containing the text "myTextCommands", without the quotes.
' https://stackoverflow.com/questions/8884728/wmi-remote-process-to-copy-file
strCommand = "cmd /c echo myTextCommands > c:\temp\testscript.txt"
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set objProcess = objWMIService.Get("Win32_Process")
errReturn = objProcess.Create(strCommand, null, null, intProcessID)
' See following link for error codes returned by errReturn
' http://msdn.microsoft.com/en-us/library/windows/desktop/aa389388(v=vs.85).aspx
Notice the important limitation in the script above: it can only create ASCII files - not binary.
Let's use that technique to map a drive letter:
strCommand = "cmd /c net use z: " & MyShare & " /user:%USERDOMAIN%\%USERNAME% " _
& strPassword & ">" & strRemoteLog
Set objProcess = objWMIService.Get("Win32_Process")
Call errProcess
where "strRemoteLog" is set to something like "c:\temp\MyLog.txt", "strPassword" is prompted (see full script example and reference at bottom), and "errProcess" is a subroutine that runs the following process using the "cmd /c" trick mentioned above:
Sub errProcess
errReturn = objProcess.Create(strCommand, null, null, intProcessID)
If errReturn = 0 Then
Wscript.Echo "Process was started with a process ID: " & intProcessID
WScript.Sleep 5000
Else
Wscript.Echo "Process could not be started due to error: " & errReturn
End If
End Sub
With a network drive mapped, copy your script to the host:
strCommand="cmd /c xcopy Z:\scripts\SCRIPT1.bat c:\temp\ >>" & strRemoteLog
Call errProcess
SCRIPT1.bat is ready, so start psexec against it on the remote host, passing your script a variable strUserID that would be obtained earlier and is here for example:
strCommand="cmd /c Z:\psexec \\%COMPUTERNAME% /accepteula -s -n 120 " _
& cmd /c c:\temp\SCRIPT1.bat " & strUserID & ">>" & strRemoteLog
Call errProcess
Once psexec finishes, you might want to save the results. So you rename the log file, upload it, unmap your drive, and clean up residual files:
strCommand="cmd /c REN " & strRemoteLog & " SCRIPT1-%COMPUTERNAME%.txt"
Call errProcess
strCommand="cmd /c MOVE /Y c:\temp\SCRIPT1*.txt Z:\scripts\LOGS\"
Call errProcess
strCommand="cmd /c net use * /del /Y"
Call errProcess
strCommand="cmd /c del c:\temp\SCRIPT1*.bat /q"
Call errProcess
You're done. You've successfully mapped a drive, run a routine script against the remote host, and uploaded its output.
Note this method also works on Windows 7 and Windows 2008 with UAC.
Here's the full 'sample' integrated script. Feel free to suggest fixes, improvements, etc.
On Error Resume Next
MyShare="\\SHARE1"
strRemoteLog="c:\temp\MapZ.txt"
' Set remote hostname
strComputer="HOST2"
'strComputer = InputBox("Enter Computer name", _
'"Find PC", strComputer)
' Set remote userid
strUserID="USERID1"
'strComputer = InputBox("Enter userid", _
'"Find User", strComputer)
' Enumerate cimv2 on remote host strComputer
Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=Impersonate}!//" & strComputer & "\root\cimv2")
' Verify remote host exists on domain
If( IsEmpty( objWMIService ) = True ) Then
WScript.Echo( "OBJECT_NOT_INITIALIZED :: " & strComputer )
WScript.Quit( OBJECT_NOT_INITIALIZED )
End If
' Prompt for masked password
strPassword=GetPass
' Build and run command to execute on strComputer
strCommand = "cmd /c net use z: " & MyShare & " /user:%USERDOMAIN%\%USERNAME% " & strPassword & ">" & strRemoteLog
Set objProcess = objWMIService.Get("Win32_Process")
Call errProcess
' Copy script(s) from MyShare to HOST2 since psexec cannot run scripts on shared drives
strCommand="cmd /c xcopy Z:\scripts\cleanpclocal.bat c:\temp\ /V /C /I /Q /H /R /Y>>" & strRemoteLog
Call errProcess
' Change directory to c:\temp
'strCommand="cmd /c cd c:\temp>" & strRemoteLog
'Call errProcess
' Start PSEXEC against script
strCommand="cmd /c Z:\psexec \\%COMPUTERNAME% /accepteula -s -n 120 cmd /c c:\temp\cleanpclocal.bat " & strUserID & ">>" & strRemoteLog
Call errProcess
' Rename logfile to include hostname, upload to share, unmap networked drive, and delete script
strCommand="cmd /c REN " & strRemoteLog & " cleanpc-%COMPUTERNAME%.txt"
Call errProcess
strCommand="cmd /c MOVE /Y c:\temp\clean*.txt Z:\scripts\LOGS\"
Call errProcess
strCommand="cmd /c net use * /del /Y"
Call errProcess
strCommand="cmd /c del c:\temp\clean*.bat /q"
Call errProcess
WScript.Quit
' ***********
' APPENDIX
' Subroutines, functions
' ***********
' **SUBROUTINES**
'strCommand="cmd /c dir z:\scripts\>" & strRemoteLog ' Works to get dir of z:\scripts\
' Function to handle errReturn
Sub errProcess
WScript.Echo "strCommand=" & strCommand
errReturn = objProcess.Create(strCommand, null, null, intProcessID)
If errReturn = 0 Then
Wscript.Echo "Process was started with a process ID: " & intProcessID
WScript.Sleep 5000
Else
Wscript.Echo "Process could not be started due to error: " & errReturn
End If
WScript.Echo
' Error return codes for Create method of the Win32_Process Class
' http://msdn.microsoft.com/en-us/library/windows/desktop/aa389388(v=vs.85).aspx
' 0=Successful Completion
' 2=Access Denied
' 3=Insufficient Privilege
' 8=Unknown failure
' 9=Path Not Found
' 21=Invalid Parameter
End Sub
' **FUNCTIONS**
' Subroutine to get masked password
Function GetPass
' Mask Passwords Using Internet Explorer
' Ensure you follow the technet.com instructions and create file password.htm
' http://blogs.technet.com/b/heyscriptingguy/archive/2005/02/04/how-can-i-mask-passwords-using-an-inputbox.aspx
Set objExplorer = WScript.CreateObject _
("InternetExplorer.Application", "IE_")
objExplorer.Navigate "file:///C:\SCRIPTS\password.htm"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width = 400
objExplorer.Height = 350
objExplorer.Left = 300
objExplorer.Top = 200
objExplorer.Visible = 1
Do While (objExplorer.Document.Body.All.OKClicked.Value = "")
Wscript.Sleep 250
Loop
strPassword = objExplorer.Document.Body.All.UserPassword.Value
strButton = objExplorer.Document.Body.All.OKClicked.Value
objExplorer.Quit
Wscript.Sleep 250
If strButton = "Cancelled" Then
Wscript.Quit
'Else
' Wscript.Echo strPassword
End If
' Return the password
GetPass = strPassword
End Function
Firstly, I think there's a typo in your code where you've written:
errResults = objFolder.Copy("f:\temp\test1.txt")
I think you meant:
errResults = objFiles.Copy("f:\temp\test1.txt")
Secondly, I don't know if what you're trying to do is possible. I think the code you've got might copy a file from a directory on the remote computer to another directory on the remote computer.
For a solution though, if WMI is available remotely on all the computers, that means that at least one port is open. If that's the case, are there any other ports that are open? If so, maybe you could set up a FTP server on your admin host on port X and then have the other hosts send the file by automating the default XP FTP client.
I know this question is old, but came across is when I was trying to find a solution so figured would direct people to an answer I wrote up and posted here:
.NET - Copying an executable across LAN to another computer, and executing it
In short, it is possible to echo base64 conversion of any file (including an exe) using WMI and then decode it with certutil.
Have you tried the following ?
set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile "f:\temp\test1.txt", "\\HOST1\C$\temp\test1.txt", true
WMI is a database of information. You cannot use it to copy files.