By default any process you start through Process.Start()
gets the same working directory as your application. The dsmod.exe
file is most likely located in System32
, so you've got to set the new process's working directory to that in order for it to find the file.
Dim psi As New ProcessStartInfo("cmd.exe", "/k dsmod user " & """" & "CN=admin,OU=Admins,OU=Users,DC=DOMAIN,DC=LOCAL" & """" & " -pwd " & TextBox1.Text)
psi.WorkingDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "System32")
Process.Start(psi)
I also took the liberty of removing the extra double quote you put at the end of the arguments since it had no matching starting quote.
NOTE: Since the system folder might be located on a different drive than the C:\
drive, I used this code:
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "System32")
in order to dynamically get the System32
folder of the current system. So for instance if the system drive has the letter D:\
, this code will return D:\Windows\System32
.
EDIT:
It appears that dsmod
is only available in the 64-bit system directory. If your application is a 32-bit app it will also start a 32-bit version of CMD (located in SysWOW64
), so you've got to force it to open the 64-bit version that's located in the System32
directory. To do this you've got to specify the full path of CMD, but in the Sysnative
directory.
By specifying Sysnative
instead of System32
you stop the system from redirecting you to the SysWOW64
directory for your 32-bit app.
Dim CmdPath As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), If(Environment.Is64BitProcess OrElse Environment.Is64BitOperatingSystem = False, "System32", "Sysnative"), "cmd.exe")
Dim psi As New ProcessStartInfo(CmdPath, "/k dsmod user " & """" & "CN=admin,OU=Admins,OU=Users,DC=DOMAIN,DC=LOCAL" & """" & " -pwd " & TextBox1.Text)
psi.WorkingDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "System32")
Process.Start(psi)