Send DOS command with VB.NET
Posted on 2004-10-06
I'm trying to execute a DOS command, the "net use" command, but all my efforts worth nothing as of this day... I tried a process, the "Shell" function, the "ShellExecute" function... nothing woked. Sometimes the command is likely to work but it never returns when i put a "waitForExit" like statement. my lastest but meaningless effort is:
Public Function createDrive() As Boolean
Dim mapDriveProcess As Process
Dim logicalDrives As Long
Dim drive As String = Nothing
Dim cpt As Long
If Not File.Exists("C:\WINNT\SYSTEM32\net.exe") Then
lblError.Text = "Could not locate drive mapping tool. Contact Patrick Poulin."
mapDriveProcess = New Process
mapDriveProcess.StartInfo.FileName = "C:\WINNT\system32\cmd.exe"
mapDriveProcess.StartInfo.Arguments = "/C net use B: \\alyson\public\webprod"
mapDriveProcess.StartInfo.UseShellExecute = False
'get the available drives to bound to
logicalDrives = GetLogicalDrives
For cpt = 0 To 25
If (logicalDrives And 2 ^ cpt) = 0 Then
drive = Chr(65 + cpt)
setDrive(drive + ":")
Catch ex As Exception
lblError.Text = "An error as occured during the binding process."
this function never returns from the "mapDriveProcess.WaitForExit()" statement. I also tried:
mapDriveProcess.StartInfo.FileName = "C:\WINNT\system32\net.exe"
mapDriveProcess.StartInfo.Arguments = "net use B: \\alyson\public\webprod" ...
any help would be appreciated !