Hi folks,
I am having problem with executing a program that uses a cmd command to run through the Visual Basic .Net. The code is as following
Dim myThemeProcess As New Process
Dim myTheme As New ProcessStartInfo
myTheme.FileName = "%SystemRoot%\system32\rundll32.exe %SystemRoot%\system32\shell32.dll,Control_RunDLL %SystemRoot%\system32\desk.cpl desk,@Themes /Action:OpenTheme /file:""" + filePath + """"
'myTheme.RedirectStandardInput = True
'myTheme.RedirectStandardOutput = True
'myTheme.UseShellExecute = False
myThemeProcess.StartInfo = myTheme
myThemeProcess.Start()
The exception comes at the last line. Can anyone help me?
Loading
Sam HobbsPosted Aug 25, 2010, 2:50 PM
http://www.altavista.com/web/results?fr=altavista&itag=ody&q=rundll32++shell32+Control_RunDLL+theme+ProcessStartInfo&kgs=1&kls=0
The following works; I tested it.
Dim myThemeProcess As New Process
Dim myTheme As New ProcessStartInfo
Dim filePath As String = "C:\Windows\Resources\Themes\characters.theme"
Dim Arguments As String = "C:\Windows\system32\shell32.dll,Control_RunDLL C:\Windows\system32\desk.cpl desk,@Themes /Action:OpenTheme /file:""" + filePath + """"
myTheme.FileName = "C:\Windows\system32\rundll32.exe"
myTheme.Arguments = Arguments
myThemeProcess.StartInfo = myTheme
myThemeProcess.Start()
Sam HobbsPosted Aug 25, 2010, 7:29 PM
Farrukh JaveidPosted Aug 25, 2010, 6:04 PM
Sam HobbsPosted Aug 25, 2010, 6:03 PM
Farrukh JaveidPosted Aug 25, 2010, 5:50 PM
I asked a silly question. The problem is I want to use the method SendKeys.Send("Enter") to the new window which is the Display Properties window but I get the Window handle of Choose the Theme Dialog box. How do I get the Window handle or the Window ID of the Display Properties window?
Sam HobbsPosted Aug 25, 2010, 5:45 PM
Instead of calling Sleep after calling myThemeProcess.Start(), I think you want to call myThemeProcess.WaitForInputIdle. After that, you can enumerate all top-level windows in the system; the window you want is the window with a process handle (or process id, I forget the details) that matches the process that was started by myThemeProcess.
Farrukh JaveidPosted Aug 25, 2010, 3:52 PM
I hope you can understand what I am trying to do. I have one last thing to ask you to help me. I am trying to check whether my active window is "Display Properties" but cant get it. I have the code to check out which helps sending the title of active window.
Private Sub OFD_BrowseTheme_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OFD_BrowseTheme.FileOk
Dim filePath As String
filePath = OFD_BrowseTheme.FileName.ToString()
Dim myThemeProcess As New Process
Dim myTheme As New ProcessStartInfo
Dim filePath1 As String = "C:\Windows\Resources\Themes\characters.theme"
Dim Arguments As String = "C:\Windows\system32\shell32.dll,Control_RunDLL C:\Windows\system32\desk.cpl desk,@Themes /Action:OpenTheme /file:""" + filePath + """"
myTheme.FileName = "C:\Windows\system32\rundll32.exe"
myTheme.Arguments = Arguments
myThemeProcess.StartInfo = myTheme
System.Threading.Thread.Sleep(2000)
myThemeProcess.Start()
System.Threading.Thread.Sleep(4000)
SendEnterKey()
End Sub
The code to view the title of active window.
Declare Function GetActiveWindow Lib "user32.dll" () As Integer
Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As System.Text.StringBuilder, ByVal cch As Integer) As Integer
Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As Integer) As Integer
Private Sub SendEnterKey()
Dim hwnd As Integer = GetActiveWindow
Dim sBuild As New System.Text.StringBuilder(GetWindowTextLength(hwnd) + 1)
GetWindowText(hwnd, sBuild, sBuild.Capacity)
MessageBox.Show(sBuild.ToString)
End Sub
Need help my friend!
Sam HobbsPosted Aug 25, 2010, 3:39 PM
The main problem is that you need to pass the arguments as a separate property.
Farrukh JaveidPosted Aug 25, 2010, 3:12 PM
Thank you very much, you are a life save :).
Can you explain a bit what was the problem with code? I am novice in VB .Net :D
Manikavelu VelayuthamPosted Aug 25, 2010, 2:54 AM