Jump to content

Recommended Posts

Posted

Can anyone help me convert the following batch file to vbs? I have limited knowledge on vbs.

 

 

@ECHO OFF

REM --- Check for an existing installation of Sophos AutoUpdate

if exist "C:\Program Files\Sophos\AutoUpdate\ALsvc.exe" goto _End

REM --- Deploy to Windows 2000/XP/2003

\\\InterChk\ESXP\Setup.exe -updp "\\\InterChk\ESXP" -user "USER" -pwd "PWD" -mng yes

REM --- End of the script

:_End

Posted

Something like this?

 

' Check for an existing installation of Sophos AutoUpdate
Set objFSO = CreateObject("Scripting.FileSystemObject")

If Not objFSO.FileExists("C:\Program Files\Sophos\AutoUpdate\ALsvc.exe") Then
	'Not found so install Sophos now.

   WshShell.Run "\\\InterChk\ESXP\Setup.exe -updp ""\\\InterChk\ESXP"" -user ""USER"" -pwd ""PWD"" -mng yes"
Else
   Wscript.Echo "ExE already exists"
End If

 

 

Not sure if that will work or if I've escaped the quotes in there properly but it should at least give you an idea..

  • 4 weeks later...
Posted
Something like this?

 

Else
   Wscript.Echo "ExE already exists"
End If

 

 

 

I think it looks fine - it's much like what we do. The only thing I wouldn't do is the wscript.echo

 

if you've got wscript as the default host then that will pop up a message box; if you're doing this in a machine startup script then that's a Really Bad Idea :-)

Posted

I think you missed this bit at the start of the code:

 

Set WshShell = WScript.CreateObject("WScript.Shell")

 

I would also add at the end to clean up:

 

Set WshShell = nothing
Set objFSO = nothing

Posted

Use this little function I have for logging to the event log:

function LogtoEvent (MSG,success)
select case success
	case 1	objShell.LogEvent EVENT_SUCCESS, MSG ' 1 is a success
	case 0	objShell.LogEvent EVENT_FAILURE, MSG ' 0 is a error
	case 2	objShell.LogEvent EVENT_WARNING, MSG ' 2 is a warning
	case 3	objShell.LogEvent EVENT_INFORMATION, MSG
end select
end function

This assumes you are declaring objShell as

Set objShell = wscript.createObject("wscript.shell")

you just call LogtoEvent in your script like so:

LogtoEvent "THE MESSAGE",1

 

You dont need to really clear variables as you only really do that if they are not needed again in the script but there is not much point if its the end anyway as it will be free automatically once the script is done.

 

BTW I think the difference between Set objFSO = CreateObject("Scripting.FileSystemObject") and wscript.shell is that the FSO has more functions for file system operations but I am not sure.

Also Scripting.FileSystemObject probably cant access the event log. I would probably use both to be safe.

Posted

I have a similar problem, if you don't mind me hijacking this thread.

 

I need to run a vbs script at logon which replicates what I can do as an administrator with this bat file:

 

xcopy "c:\itunefiles\*.*" "%userprofile%\*.*" /E /Y

 

As it will be running at logon for all machines I would need to only run it if the folder c:\itunefiles exists. This will copy the preferences I've set for ITunes into the student profiles and hopefully allow ITunes to run in a locked down environment.

Posted

In my experience, copying files from VBS is not that reliable. I've had to build my own recursive file copy function to really do the job well and be able to report reasonably when things go wrong.

 

For file copying, I would be inclined to write a script which called ROBOCOPY to do the actual copying work and then analyse the return code.

 

One of the nice things about ROBOCOPY is that it can keep a local folder in sync with a network folder without re-copying files that are already in both folders and have not changed in either.

Posted
I can't run any commandline script, as access to command is blocked for the student, as as the script has to run after they log on it needs to run under their permissions.
Posted
I can't run any commandline script, as access to command is blocked for the student, as as the script has to run after they log on it needs to run under their permissions.

 

By executing a copy of ROBOCOPY, you are not running a command line script. ROBOCOPY is an executable program that does not rely on a command line to host it's output. This won't get around the fact that it has to run in the same security context as the user that is logging on of course any more that the VB script would.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...