Simple Code Work Nice On Window XP But Not On Windows 7
I am facing a very weird issue and found no clue why?
that's why i comes here for a reason for the issue..
let me explain; i am trying following code to run a process (Open Printer Preferences Window) and get the Window Handle For Further Processing, the code runs very fine as it should on windows xp environment, but when i try on windows 7 it stuck on the do while loop as MaindWindowHandle Only Returns 0.
here is the code:
Code:
Dim objProcess As System.Diagnostics.Process
Dim intHwnd As IntPtr
objProcess = New System.Diagnostics.Process
With objProcess.StartInfo
.FileName = "rundll32"
.Arguments = String.Format("printui.dll,PrintUIEntry /e /n {0}{1}{0}", Convert.ToChar(34), "EPSON L130 Series")
.UseShellExecute = False
End With
objProcess.Start()
Do While objProcess.MainWindowHandle = IntPtr.Zero //Windows 7 Execution Trapped In This Loop
System.Threading.Thread.Sleep(500)
objProcess.Refresh()
My.Application.DoEvents()
Loop
intHwnd = objProcess.MainWindowHandle
objProcess.Dispose()
objProcess = Nothing
MessageBox.Show(intHwnd.ToString)
any idea?
thanks in advance
best regards
Re: Simple Code Work Nice On Window XP But Not On Windows 7
Try this...
Code:
Dim objProcess As New Process
Dim intHwnd As IntPtr
With objProcess.StartInfo
.FileName = "rundll32"
.Arguments = String.Format("printui.dll,PrintUIEntry /e /n {0}{1}{0}", Convert.ToChar(34), "EPSON L130 Series")
.UseShellExecute = False
End With
objProcess.Start()
objProcess.WaitForInputIdle()
intHwnd = objProcess.MainWindowHandle
objProcess.Dispose()
MessageBox.Show(intHwnd.ToString)
Re: Simple Code Work Nice On Window XP But Not On Windows 7
Quote:
Originally Posted by
.paul.
Try this...
Code:
.....
objProcess.WaitForInputIdle()
.....
first of all thanks a lot for your kind reply, second sir, i am very sorry as i forgot to mention in my post that, after a google search i found that one, and tried that too.. but that didn't work either :( returning 0 as window handle :(
thanks again for your reply though...
Re: Simple Code Work Nice On Window XP But Not On Windows 7
Does the process you’re starting have a window?
Re: Simple Code Work Nice On Window XP But Not On Windows 7
Quote:
Originally Posted by
.paul.
Does the process you’re starting have a window?
thanks for your reply sir..
yes sir, it does...
it the very same window/GUI interface if you right click on "Printer" and select "Printing Preferences"
best regards