Results 1 to 5 of 5

Thread: Simple Code Work Nice On Window XP But Not On Windows 7

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2009
    Posts
    337

    Exclamation 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

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,226

    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)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2009
    Posts
    337

    Re: Simple Code Work Nice On Window XP But Not On Windows 7

    Quote Originally Posted by .paul. View Post
    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...

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,226

    Re: Simple Code Work Nice On Window XP But Not On Windows 7

    Does the process you’re starting have a window?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2009
    Posts
    337

    Re: Simple Code Work Nice On Window XP But Not On Windows 7

    Quote Originally Posted by .paul. View Post
    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width