Results 1 to 5 of 5

Thread: [RESOLVED] Help with "net use" syntax in VBScript program

  1. #1

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a new Maserati down a dead end street
    Posts
    4,305

    Resolved [RESOLVED] Help with "net use" syntax in VBScript program

    I have a question about how to run a net use command in a vbscript program. It is easy enough to find online the net use command but I will also need to provide an id and password. So it starts out something like this:
    Code:
    dim oShell
    Set oShell = CreateObject("WScript.Shell")
    oShell.Run "NET USE X: \\server\shared_folder"
    but then what would it be exactly ..."/user:user_id /passwordassword"?

    Thanks.
    Last edited by MMock; Mar 5th, 2010 at 01:42 PM. Reason: typo
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  2. #2

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a new Maserati down a dead end street
    Posts
    4,305

    Re: Help with "net use" syntax in VBScript program

    It turned my colon-p into an obnoxious face, sorry...
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  3. #3

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a new Maserati down a dead end street
    Posts
    4,305

    Re: Help with "net use" syntax in VBScript program

    I've got the net use working with the id and password but what I want to do after that is copy a file from "program files" on the source to a folder on the dest. I think I am having a problem with the space in "program files". How do I handle the space - I think I want quotes around the whole thing (like you would do in File->Run), but then there has to be quotes around the string in VB.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  4. #4

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a new Maserati down a dead end street
    Posts
    4,305

    Re: Help with "net use" syntax in VBScript program

    This is my code and it doesn't work. For now, I took out the "Program Files" issue and just put the source file on the D: drive root. The file is not copied. I get an error written to the log which is the number -2147024894 which I think is "system cannot find the file specified". However, if I run the same commands in a DOS prompt which I am executing in the code, the file copies fine.
    Code:
    Option Explicit
    
    on error resume next
    dim fso, logFile
    set fso = createObject("Scripting.FileSystemObject")
    set logFile = fso.openTextFile("D:\Program Files\NymexSettle\log (" & replace(replace(now(),"/","-"),":"," ") & ").log", 8, true)
    logFile.writeLine "program start"
    
    'Join a password protected file share (Drive MAP)
    ' NET USE [driveletter:] \\ComputerName\ShareName[\volume] [password | *] [/USER:[domainname\]username] 
     
    dim oShell
    Set oShell = CreateObject("WScript.Shell")
    oShell.Run "NET USE X: \\server pw /user:id" 
    If err.number <> 0 then
        Logfile.writeline err.description
        Logfile.writeline err.number
    Else
        dim strCommand
        ' strCommand = "copy " & chr(34) & "d:\program files\Nymexsettle\TestWithMe.txt" & chr(34) & " x:"  
        strCommand = "copy d:\TestWithMe.txt x:"
        oShell.Run strCommand        
        If err.number <> 0 then
    	Logfile.writeline strCommand
    	Logfile.writeline err.description
    	Logfile.writeline err.number
        End If
    End if
    logFile.writeLine "program stop"
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  5. #5

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a new Maserati down a dead end street
    Posts
    4,305

    Re: Help with "net use" syntax in VBScript program

    Here is my working script which performs a net use to a password-protected folder on the destination server and copies a file.
    Code:
    Option Explicit
    
    on error resume next
    dim fsoLog, logFile
    set fsoLog = createObject("Scripting.FileSystemObject")
    set logFile = fsoLog.openTextFile("D:\Program Files\NymexSettle\log (" & replace(replace(now(),"/","-"),":"," ") & ").log", 8, true)
    logFile.writeLine "program start"
    
    'Join a password protected file share (Drive MAP)
    ' NET USE [driveletter:] \\ComputerName\ShareName[\volume] [password | *] [/USER:[domainname\]username] 
     
    dim objNetwork
    Set objNetwork = CreateObject("Wscript.Network")
    objNetwork.MapNetworkDrive "X:", "\\server\folder", False, "my id", "my password"
    If err.number <> 0 then
        Logfile.writeline err.description
        Logfile.writeline err.number
    Else
        Dim oFSO     
        Set oFSO = CreateObject("scripting.FileSystemObject")
        oFSO.CopyFile "d:\program files\Nymexsettle\TestWithMe.txt", "x:\TestWithMe.txt"
    
        If err.number <> 0 then
    	Logfile.writeline strCommand
    	Logfile.writeline err.description
    	Logfile.writeline err.number
        End If
    End if
    
    objNetwork.RemoveNetworkDrive "X:"
    
    logFile.writeLine "files copied ~ network drive removed ~ quitting"
    Wscript.Quit
    Thanks for letting me work it out on my own.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

Posting Permissions

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



Click Here to Expand Forum to Full Width