+ Post New Thread
Results 1 to 13 of 13
Scripts Thread, Covert CMD/BAT files to vbs help in Coding and Web Development; Can anyone help me convert the following batch file to vbs? I have limited knowledge on vbs. @ECHO OFF REM ...
  1. #1
    tosca925's Avatar
    Join Date
    Aug 2005
    Location
    Midlands
    Posts
    1,547
    Thank Post
    4
    Thanked 4 Times in 4 Posts
    Rep Power
    22

    Covert CMD/BAT files to vbs help

    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
    \\<SERVER>\InterChk\ESXP\Setup.exe -updp "\\<SERVER>\InterChk\ESXP" -user "USER" -pwd "PWD" -mng yes
    REM --- End of the script
    :_End

  2. #2
    contink's Avatar
    Join Date
    Jul 2006
    Location
    South Yorkshire
    Posts
    3,791
    Thank Post
    303
    Thanked 327 Times in 233 Posts
    Rep Power
    118

    Re: Covert CMD/BAT files to vbs help

    Something like this?

    Code:
    ' 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 "\\<SERVER>\InterChk\ESXP\Setup.exe -updp ""\\<SERVER>\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..

  3. #3
    projector1's Avatar
    Join Date
    Nov 2005
    Posts
    460
    Thank Post
    70
    Thanked 1 Time in 1 Post
    Rep Power
    18

    Re: Covert CMD/BAT files to vbs help

    interested to see if it worked!

  4. #4

    mattx's Avatar
    Join Date
    Jan 2007
    Posts
    9,236
    Thank Post
    1,057
    Thanked 1,067 Times in 624 Posts
    Rep Power
    740

    Re: Covert CMD/BAT files to vbs help

    Just out of interest why do you want to convert it ? As the saying says, if it ain't broke......

  5. #5

    ZeroHour's Avatar
    Join Date
    Dec 2005
    Location
    Edinburgh, Scotland
    Posts
    5,630
    Thank Post
    890
    Thanked 1,314 Times in 798 Posts
    Blog Entries
    1
    Rep Power
    441

    Re: Covert CMD/BAT files to vbs help

    BTW you are not supposed to need a script to deploy sophos anymore in EM console 3.

  6. #6

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,154
    Thank Post
    114
    Thanked 527 Times in 450 Posts
    Blog Entries
    2
    Rep Power
    123

    Re: Covert CMD/BAT files to vbs help

    Quote Originally Posted by contink
    Something like this?

    Code:
    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 :-)

  7. #7
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    41

    Re: Covert CMD/BAT files to vbs help

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

    Code:
    Set WshShell = WScript.CreateObject("WScript.Shell")
    I would also add at the end to clean up:

    Code:
    Set WshShell = nothing
    Set objFSO = nothing

  8. #8

    ZeroHour's Avatar
    Join Date
    Dec 2005
    Location
    Edinburgh, Scotland
    Posts
    5,630
    Thank Post
    890
    Thanked 1,314 Times in 798 Posts
    Blog Entries
    1
    Rep Power
    441

    Re: Covert CMD/BAT files to vbs help

    Use this little function I have for logging to the event log:
    Code:
    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
    Code:
    Set objShell = wscript.createObject("wscript.shell")
    you just call LogtoEvent in your script like so:
    Code:
    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.

  9. #9
    clareq's Avatar
    Join Date
    Dec 2005
    Location
    Doncaster
    Posts
    673
    Thank Post
    51
    Thanked 179 Times in 116 Posts
    Rep Power
    85

    Re: Covert CMD/BAT files to vbs help

    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.

  10. #10
    ajbritton's Avatar
    Join Date
    Jul 2005
    Location
    Wandsworth
    Posts
    1,632
    Thank Post
    23
    Thanked 75 Times in 45 Posts
    Rep Power
    34

    Re: Covert CMD/BAT files to vbs help

    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.

  11. #11
    clareq's Avatar
    Join Date
    Dec 2005
    Location
    Doncaster
    Posts
    673
    Thank Post
    51
    Thanked 179 Times in 116 Posts
    Rep Power
    85

    Re: Covert CMD/BAT files to vbs help

    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.

  12. #12
    ajbritton's Avatar
    Join Date
    Jul 2005
    Location
    Wandsworth
    Posts
    1,632
    Thank Post
    23
    Thanked 75 Times in 45 Posts
    Rep Power
    34

    Re: Covert CMD/BAT files to vbs help

    Quote Originally Posted by clareq
    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.

  13. #13
    clareq's Avatar
    Join Date
    Dec 2005
    Location
    Doncaster
    Posts
    673
    Thank Post
    51
    Thanked 179 Times in 116 Posts
    Rep Power
    85

    Re: Covert CMD/BAT files to vbs help

    Robocopy was the charm, I think - thank you.

SHARE:
+ Post New Thread

Similar Threads

  1. MSI Files.
    By boomam in forum How do you do....it?
    Replies: 14
    Last Post: 9th November 2007, 12:50 PM
  2. .nrg files HELP!
    By thegrassisgreener in forum Windows
    Replies: 5
    Last Post: 6th September 2007, 06:57 PM
  3. WDS and .WIM files.
    By starscream in forum Wireless Networks
    Replies: 1
    Last Post: 4th July 2007, 02:37 PM
  4. exe files on usb sticks
    By goodhead in forum Hardware
    Replies: 4
    Last Post: 15th February 2007, 05:18 PM
  5. Preview PSD files
    By ZeroHour in forum Windows
    Replies: 0
    Last Post: 4th July 2006, 01:50 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •