Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


New in VBScript - Needs help...

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,59819
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> New in VBScript - Needs help...
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 New in VBScript - Needs help... - 5/5/2008 2:16:30 AM   
  Futur2008

 

Posts: 4
Score: 0
Joined: 5/5/2008
Status: offline
Hello,

I'm new User in VBscript. I have a batch file and I need to converted to a vbscript.
The command in the batch file in the following
call "Z:\EFS\EFS_LOG\AR\efsinfo.exe" /r /s:"C:\Documents and Settings\%Username%\My Documents" /i >"Z:\EFS\EFS_LOG\AR\%Username%.log".
It means thatI should run
Z:\EFS\EFS_LOG\AgentRecovery\efsinfo.exe /r /s:"C:\Documents and Settings\%Username%\My Documents" /i
then I want to write the result in a new file or existing file %Username%.log" which is located in Z:\EFS\EFS_LOG\AgentRecovery\"
Thanks
Futur
 
 
Post #: 1
 
 RE: New in VBScript - Needs help... - 5/5/2008 2:27:29 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Read the two threads that are in my signature, get the WSH documentation, research the .Run method of the WShell object, search here for examples, write some code, then post back here with questions or problems.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Futur2008)
 
 
Post #: 2
 
 RE: New in VBScript - Needs help... - 5/5/2008 3:10:21 AM   
  Futur2008

 

Posts: 4
Score: 0
Joined: 5/5/2008
Status: offline
I already write some line but it does not work

Option Explicit
Dim objShell
Dim fso, f, objShell
Set objShell = CreateObject("WScript.Shell")
objShell.Run ("Z:\EFS\EFS_LOG\AR\efsinfo.exe" & " /r" & " /s:" &"C:\Documents and Settings\%Username%\My Documents" &" /i")
Set f = fso.OpenTextFile("Z:\EFS\EFS_LOG\AR\%Username%.log", 8, True)
f.write ("Z:\EFS\EFS_LOG\AR\%Username%.log")
WScript.Quit

Thanks

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: New in VBScript - Needs help... - 5/5/2008 3:20:05 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
There are several threads in the forum relating to running commands and the use of double quotes ("). Try searching around.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Futur2008)
 
 
Post #: 4
 
 RE: New in VBScript - Needs help... - 5/5/2008 3:39:05 AM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi Futur2008,

to run a working/tested command line/batch statement from VBScript, follow these steps:

(1) execute the line from a DOS-Box

      "Z:\EFS\EFS_LOG\AR\efsinfo.exe" /r /s:"C:\Documents and Settings\%Username%\My Documents" /i >"Z:\EFS\EFS_LOG\AR\%Username%.log"

    (I assume that exactly this works on your computer)

(2) Copy the line into your script:

     Dim sCmd
     sCmd = "Z:\EFS\EFS_LOG\AR\efsinfo.exe" /r /s:"C:\Documents and Settings\%Username%\My Documents" /i >"Z:\EFS\EFS_LOG\AR\%Username%.log"

(3) Put " around the copy and double all exsisting "

     Dim sCmd
      sCmd = """Z:\EFS\EFS_LOG\AR\efsinfo.exe"" /r /s:""C:\Documents and Settings\%Username%\My Documents"" /i >""Z:\EFS\EFS_LOG\AR\%Username%.log"""

(3) Get the variable info into (a) variable(s) and put placeholder(s) into sCmd; in your case %Username% could be used as placeholder,
     but I use @UN@ to better illustrate this step

     Dim sUserName
     sUserName = ... left as exercise ...
      sCmd = """Z:\EFS\EFS_LOG\AR\efsinfo.exe"" /r /s:""C:\Documents and Settings\@UN@\My Documents"" /i >""Z:\EFS\EFS_LOG\AR\@UN@.log"""

(4) Because you need a shell for the device rerouting prepend "%comspec% /c "

      sCmd = "%comspec% /c ""Z:\EFS\EFS_LOG\AR\efsinfo.exe"" /r /s:""C:\Documents and Settings\@UN@\My Documents"" /i >""Z:\EFS\EFS_LOG\AR\@UN@.log"""

(5) call Replace for each placeholder-variable-pair:

     sCmd = Replace( sCmd, "", sUserName )   ' <----  function call: param list ()

(6) Echo sCmd to check

     WScript.Echo sCmd

(7) Call .Run:

     objShell.Run sCmd   ' <---- sub call: no param list ()

(8) Think about the additional parameters to .Run and/or whether .Exec is better suited to your needs

[air code; I may have messed up the darned "]

Good luck!

ehvbs



(in reply to Futur2008)
 
 
Post #: 5
 
 RE: New in VBScript - Needs help... - 5/7/2008 3:54:54 AM   
  Futur2008

 

Posts: 4
Score: 0
Joined: 5/5/2008
Status: offline
Hello,
Here is my script
******************
quotes = chr(34)
Dim objShell
Dim objNetwork
Dim sCmd
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
strUserName = objNetwork.UserName
sCmd = "Z:\EFS\EFS_LOG\AR\efsinfo.exe /r /s:" & quotes & "C:\Documents and Settings\" & strUserName & "\My Documents" & quotes & "/i >
Z:\EFS\EFS_LOG\AR\" & strUserName & ".log"
Wscript.Echo "User Name: " & strUserName
WScript.Echo "Command Line: "& sCmd
WScript.Echo "Will now run the command line!"
objShell.Run sCmd
******************
When I run it I don't have an error message but my log file does not create in Z:\EFS\EFS_LOG\AR\.
Somehow if I type my command in the DOS prompt,
"Z:\EFS\EFS_LOG\AR\efsinfo.exe" /r /s:"C:\Documents and Settings\%Username%\My Documents" /i >"Z:\EFS\EFS_LOG\AR\%Username%.log"
everything is OK which mean the log file is created.
What's wrong with my script?

(in reply to ehvbs)
 
 
Post #: 6
 
 RE: New in VBScript - Needs help... - 5/7/2008 5:33:05 AM   
  chiltz

 

Posts: 72
Score: 0
Joined: 6/13/2007
Status: offline
my guess would be you are missing a space

You have = "\My Documents" & quotes & "/i >
Should Be = "\My Documents " & quotes & "/i >
Or Should Be = "\My Documents" & quotes & " /i >

Notice thte space after the "S" in documents" or before the "/" in /i

(in reply to Futur2008)
 
 
Post #: 7
 
 RE: New in VBScript - Needs help... - 5/7/2008 4:48:51 PM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
The problem with using concatenation to insert quotes into strings - instead of applying
step (3) - is that the 'code noise' of " & Chr( 34 ) & " (or variations of that) distract from
the format of the string:

You have = "\My Documents" & quotes & "/i >          ==> \My Documents"/i
Should Be = "\My Documents " & quotes & "/i >        ==> \My Documents "/i    so this is wrong too!
Or Should Be = "\My Documents" & quotes & " /i >   ==> \My Documents" /i

The risk of such errors is less if you write

  ... \My Documents"" /i >  ....

The "" may look ugly, but a missing space is much easier to spot:

  ... \My Documents""/i >  ....              <== bad; missing space before /i







(in reply to chiltz)
 
 
Post #: 8
 
 RE: New in VBScript - Needs help... - 5/13/2008 5:55:25 AM   
  Futur2008

 

Posts: 4
Score: 0
Joined: 5/5/2008
Status: offline
Thanks for everyone.
Here is my script
quotes = chr(34)
Dim objShell
Dim objNetwork
Dim sCmd
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
strUserName = objNetwork.UserName
sCmd = "cmd /c " & quotes & "Z:\EFS\EFS_LOG\AR\efsinfo.exe /r /i /s:" & quotes & "C:\Documents and Settings\" & strUserName & "\My Documents" & quotes & " > " & quotes & "Z:\EFS\EFS_LOG\AR\" & strUserName & ".log" & quotes
objShell.Run (sCmd),0,True

(in reply to ehvbs)
 
 
Post #: 9
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> New in VBScript - Needs help... Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts