PSTools and VB.net: The system cannot find the file specified - vb.net

Im trying to write a program, for work, that will be able to tell me if one person is logged into more than one PC.
Im using PStool's PSloggedon cmd.
here is the code Im experimenting with:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim Proc As New System.Diagnostics.Process
Proc.StartInfo = New ProcessStartInfo("psLoggedon")
'right now the textbox will hold a PC ID from a list of PC's in a database.
Proc.StartInfo.Arguments = "-l \\" & TextBox1.Text & ""
Proc.StartInfo.RedirectStandardOutput = True
Proc.StartInfo.UseShellExecute = False
Proc.StartInfo.CreateNoWindow = True
Proc.Start()
MsgBox(Proc.StandardOutput.ReadToEnd)
Proc.Close()
End Sub
but I am getting this eror:
Win32Exception was unhandled:
The system cannot find the file specified
I checked here:
C:\Windows\System32
and made sure the application files were copied there and they were.
can someone help me out and explain to me what I can do to resolve this issue?
p.s. Im using windows 7

use
string filePath = Environment.GetFolderPath(Environment.SpecialFolder.Windows) + "\\sysnative";
32 bit system command

Related

VB 2013 - route add cmd elevated

After a few days of googeling and trying i thought let met ask it my self.
I am trying to make this happen:
http://gyazo.com/5274568fcb55a0fe042936e375c0b424
The show current routes is working just fine, and displays the text i ask him to show.
But the route adding not so much let me show you the code :)
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim cmdThread As New Threading.Thread(AddressOf CmdAutomate2)
cmdThread.Start()
End Sub
Private Sub CmdAutomate2()
Dim myprocess As New Process
Dim startInfo As New System.Diagnostics.ProcessStartInfo
startInfo.FileName = "cmd"
startInfo.RedirectStandardInput = True
startInfo.RedirectStandardOutput = True
startInfo.UseShellExecute = False
startInfo.CreateNoWindow = True
myprocess.StartInfo = startInfo
myprocess.Start()
Dim sR As System.IO.StreamReader = myprocess.StandardOutput
Dim sW As System.IO.StreamWriter = myprocess.StandardInput
sW.WriteLine("route add" & textbox1.text & " " & textbox2.text)
sW.WriteLine("exit") 'exits command prompt window
results = sR.ReadToEnd 'returns results of the command window
sW.Close()
sR.Close()
Invoke(finished)
End Sub
Now i know you should use different pieces of code here mainly:
startInfo.UseShellExecute = True
instead of:
startInfo.UseShellExecute = False
But that gives me errors with the redirect (which i found to be confimed as not possible somewhere else in this forum)
Now i dont care for it to show the output i have the other button for it.
But i cannot seem to et this to work as i get different errors all the time like cannot reditect ot redirect not started with different combinations of code from all over the web,,
What am i missing here??
To be able to edit the route table for your PC, your app needs to run as administrator. you can add a manifest to your application which declares that you require administrator privileges, which should prompt as required.

Opening an Empty Directory from a Windows Form - VB.net

I'm trying to open a directory via my Windows Form created in VB.Net but every solution I've found doesn't seem to work.
Currently I'm using-
Dim path As String = Directory.GetCurrentDirectory()
Private Sub logDirBTN_Click(sender As Object, e As EventArgs) Handles logDirBTN.Click
Process.Start(path + "\Resources\Logs")
End Sub
Which returns "The system cannot find the file specified" exception. That's interesting because I know the folder is there. Furthermore this button's functionality works without any issue and from what I can tell the only difference is I'm opening a text file rather than an empty directory-
Private Sub stationListBTN_Click(sender As Object, e As EventArgs) Handles stationListBTN.Click
Process.Start("notepad.exe", path + "\Resources\StationList\StationList.txt")
End Sub
Here are all the other things I've tried-
Private Sub logDirBTN_Click(sender As Object, e As EventArgs) Handles logDirBTN.Click
'Process.Start("explorer.exe", path + "\Resources\Logs")
'Shell("explorer.exe", path + "\Resources\Logs", vbNormalFocus)
'Application.StartupPath & path + "\Resources\Logs"
'Shell(path + "\Resources\Logs", vbNormalFocus)
End Sub
Any help is greatly appreciated.
Dim MyProcess As New Process()
MyProcess.StartInfo.FileName = "explorer.exe"
MyProcess.StartInfo.Arguments = "C:\Blah"
MyProcess.Start()
MyProcess.WaitForExit()
MyProcess.Close()
MyProcess.Dispose()
Or just...
Process.Start("explorer.exe", "C:\FTP\")
Application.StartupPath is going to get you to your bin\Debug or bin\Release folder by the way, whatever folder the *.exe is in.
I'm guessing this is what you're looking for:
Process.Start("explorer.exe", Application.StartupPath & "\Resources\Logs")
Also, don't use + for joining strings. Use &
I assume you are trying to invoke Windows Explorer.
Add a trailing \ in the call to .Start
IO.Directory.CreateDirectory("C:\temp\temp")
Process.Start("c:\temp\temp\")
In the OP first example you were trying to open a file 'Logs'

OpenFileDialog under the hood

This is my first question here because I ended up in dead end.
I'm using ZIP 2 Secure EXE (very good software from Chilkat) to create setup.exe for application. ZIP 2 Secure EXE can be run without GUI with one or more parameters.
The problem is that when I call ZIP 2 Secure EXE (ChilkatZipSE.exe) without using OpenFileDialog form to determine location of ChilkatZipSE.exe, it doesn't run process with System.Diagnostics.Process class. The way I call ChilkatZipSE.exe is "..\ChilkatZipSE.exe -cfg settings.xml". Everything is OK with settings.xml and there is UnlockCode node which is needed for creating setup.exe file. When I use OpenFileDialog ChilkatZipSE.exe creates desired setup.exe and it's working fine.
Bellow is my code that I use:
Private Sub btnStartApp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartApp.Click
If txtExtAppPath.Text.Length > 0 AndAlso System.IO.File.Exists(txtExtAppPath.Text) Then
Dim myFile As New FileInfo(txtExtAppPath.Text)
txtExtAppLog.Text = StartApplication(myFile.FullName, txtExtParams.Text, chkIsHidden.Checked)
'txtExtAppLog.Text = StartApplication(txtExtAppPath.Text, txtExtParams.Text, chkIsHidden.Checked)
End If
End Sub
Public Function StartApplication(ByVal fileFullPath_ As String, ByVal fileParameter_ As String, ByVal isHidden_ As Boolean) As String
Dim lassie As String = String.Empty
Try
Dim newProcess As New ProcessStartInfo()
newProcess.FileName = fileFullPath_
newProcess.Arguments = fileParameter_
If isHidden_ Then newProcess.WindowStyle = ProcessWindowStyle.Hidden
If System.IO.File.Exists(fileFullPath_) Then
Using startedNewProcess As Process = Process.Start(newProcess)
'startedNewProcess.EnableRaisingEvents = True
startedNewProcess.WaitForExit()
End Using
Else
lassie = "File " + fileFullPath_ + " doesn't exist."
End If
Catch ex As Exception
lassie = ex.Message
End Try
Return lassie
End Function
Thanks, magnumx.
the problem was the given parameter. When using OpenFileDialog it knows where settings.xml is. But when calling "..\ChilkatZipSE.exe -cfg settings.xml" without OpenFileDialog it must be used as "..\ChilkatZipSE.exe -cfg ..\settings.xml"

How to hide Windows 7 Open File Security when running certain EXE file using VB.NET?

Hello dearest community,
I am trying to build a simple AutoUpdate application using VB.NET. It was quite simple. That is, I put the newest ZIP file in my hosting site, and then download it using WebClient.DownloadFileAsync. After it get downloaded, I extract it using http://stahlforce.com/dev/unzip.exe
But each time I run the unzip.exe using Process.start, Windows 7 always show Open File Security.
Is it possible for VB.NET to bypass such security restriction?
Thanks.
Btw, this is my code of using WebClient.DownloadFileAsync, in case any one google about it and landed on this page :
Public Class AutoUpdate
Dim installationFolder As String = "C:\Program Files\xyz\abc\"
Dim updateFileNameTarget As String
Private Sub btnStartUpdte_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartUpdte.Click
lblPercent.Text = ""
lblDownloading.Text = ""
lblDownloading.Text = ""
pbDownloadStatus.Value = 0
Dim wc As New WebClient
AddHandler wc.DownloadFileCompleted, AddressOf downloadComplete
AddHandler wc.DownloadProgressChanged, AddressOf progressChanged
Dim path As String = "http://xyz.abc.com/test.zip"
updateFileNameTarget = installationFolder & "test.zip"
Try
If File.Exists(updateFileNameTarget) Then
File.Delete(updateFileNameTarget)
End If
lblDownloading.Text = "Downloading " & path
wc.DownloadFileAsync(New Uri(path), updateFileNameTarget)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub progressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
pbDownloadStatus.Value = e.ProgressPercentage
lblPercent.Text = e.ProgressPercentage & "%"
End Sub
Private Sub downloadComplete(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
MessageBox.Show("Download complete. Now extracting")
Dim cmd As String = Application.StartupPath & "\Tools\unzip.exe"
Dim arg As String = "-o """ & updateFileNameTarget & """"
Process.Start(cmd, arg)
End Sub
End Class
If you're already process-invoking everything else (including unzip), also use Sysinternal's streams.exe. Use the -d flag to remove the NTFS alternate data streams (ADS). There should only be one - and it is the one that indicates to Windows that the file was downloaded from an "untrusted source".
Your downloaded files will currently have a stream that looks like this:
:Zone.Identifier:$DATA 26
Remove this stream from the download files after extracting but before execution, and the warning will no longer appear.
See also: What is Zone Identifier? - and Accessing alternate data streams in files for a library to work with these within .NET without needing streams.exe.

Writing commands to cmd with Visual Basic

I'm using VirtualBox to attach a usb device. This usb device only works under 32 bit. My host os is Windows 7 64 bit, my Guest Windows 7 32 bit.
I found code to write to the command prompt and read it back out, this has been tested and works very well. But now after I have read and want to write again the command prompt just freezes. I have no idea why it does that... I also tried the command without VB and the driver attach fine.
Any ideas how I can solve this problem?
Public Class Form1
Private Results As String
Private test As Double
Private test2 As String
'The "Delegate" is used to correct the threading issue (Can't update control directly in VB.net 08/10), and invokes the needed text
update.
Private Delegate Sub delUpdate()
Private Finished As New delUpdate(AddressOf UpdateText)
Private Sub UpdateText()
resultsTextBox.Text = Results
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim CMDThread As New Threading.Thread(AddressOf CMDAutomate)
CMDThread.Start()
End Sub
Private Sub CMDAutomate()
Dim myprocess As New Process
Dim StartInfo As New System.Diagnostics.ProcessStartInfo
'Starts the CMD Prompt
StartInfo.FileName = "cmd.exe"
StartInfo.RedirectStandardInput = True
StartInfo.RedirectStandardOutput = True
'Required to redirect
StartInfo.UseShellExecute = False
'Disables the creation of a CMD Prompt outside application.
StartInfo.CreateNoWindow = False
myprocess.StartInfo = StartInfo
myprocess.Start()
Dim SR As System.IO.StreamReader = myprocess.StandardOutput
Dim SW As System.IO.StreamWriter = myprocess.StandardInput
'Runs the command you entered...
'SW.WriteLine(TextBox1.Text)
SW.WriteLine("cd C:\Program Files\Oracle\VirtualBox")
SW.WriteLine("vboxmanage list usbhost")
'Exits CMD Prompt
'SW.WriteLine("exit")
'Displayes the results...
Results = SR.ReadToEnd
'Im reading the string out to get the right Device id
test = InStr(Results, "0x0547", CompareMethod.Text)
test = test - 58
test2 = Mid(Results, test, 36)
'test2 gives 80be0bc1-6f69-4886-868f-c8857bff34c1
'this is the right id, if i try to input it myselves with:
'C:\Program Files\Oracle\VirtualBox>vboxmanage controlvm "test" usbattach
'80be0bc1-6f69-4886-868f-c8857bff34c1
'it works...
SW.WriteLine("vboxmanage controlvm " + Chr(34) + "test" + Chr(34) + "usbattach " + test2)
SW.WriteLine("exit")
Results = SR.ReadToEnd
SW.Close()
SR.Close()
'Invokes Finished delegate, which updates textbox with the results text
Invoke(Finished)
End Sub
End Class
I think ReadToEnd doesn't finish because the Command Window is still open. I would run half of your commands and then read it in after the EXIT command is called. Then you would simply need to parse the result string and run another Command Window process.