none
ShowWindow in CreateProcessAsUser and in StartUpInfo Structure.....

    Question

  • Hi,

    I am getting confused in these two ShowWindow properties in different places. If i start the process having .lnk extension say  "C:\Documents and Settings\All Users\Desktop\VLC media player.lnk" which will show the VLC player window.

     

    If i made showwindow false then will it make any difference?

     

    Regards,

    Paresh

    Friday, November 23, 2007 2:21 PM

Answers

  • Hi Paresh,

     

    If you have a STARTUPINFO declaration in C# with a public field named desktop, I think you can write this code line  - "startupInfo.desktop = "WinSta0\\Default";"

     

    Remarks on the lpDesktop as follows:

    The name of the desktop, or the name of both the desktop and window station for this process. A backslash in the string indicates that the string includes both the desktop and window station names. For more information, see Thread Connection to a Desktop.

    Windows Me/98/95:  Desktops and window stations are not supported.

     

    As far as I know, the "Default" application desktop will be used by all the processes for which "Winsta0\default" is specified in the STARTUPINFO.lpDesktop structure member. When the lpDesktop structure member is NULL, the window station and desktop is inherited from the parent process. All services that are executed under the LocalSystem account with the Allow Service to Interact with Desktop startup option selected will use "Winsta0\Default". All these processes will share the same desktop heap associated with the "Default" application desktop.

     

    As I understand, I think you can change the value of the lpdesktop in the STARTUPINFO structure from machine to machine. For example, you can change its value as "startUpInfo.lpDesktop = CurrentDesktopName;" or "startUpInfo.lpDesktop = null;"

     

    Hope this helps,

    Regards,

    Thursday, November 29, 2007 2:43 AM

All replies

  • Hi Paresh,

     

    I'm a bit confused with your description about two ShowWindow properties. Could you please clarify it for more details?

    You said "If i made showwindow false then will it make any difference?", what do you mean? 

    CreateProcessAsUser is used to create a new process and its primary thread. The new process runs in the security context of the user represented by the specified token. What's the relationship between CreateProcessAsUser function and two ShowWindow properties?

     

    Regards,

    Monday, November 26, 2007 7:51 AM
  • Hi,

     

    I have marked showWindow with -->

     

    First one:

     

    StartupInfo si = new StartupInfo();

    --> si.showWindow = "false";

     

    Second one: as an argument in CreateProcessAsUser

     

    bool newProcessCreated = Native.Native.CreateProcessAsUser(

     userToken,

     null,

     fcp,

     ref sa, ref sa,

     false,

     -- > ( int ) ProcessCreationFlags.CreateNoWindow | ( int ) ProcessPriorityTypes.Normal,

     IntPtr.Zero, null, ref si, out pi );

     

    Thanks,

    Paresh

    Wednesday, November 28, 2007 8:17 AM
  • Hi Paresh,

     

    As I understand, these two ShowWindow in StartupInfo structure and CreateProcessAsUser function are all used to set if you display a window or not when creating a new process.

     

    About the seventh parameter named dwCreationFlags in the CreateProcessAsUser function, you can try to refer to the following explanations from MSDN document - http://msdn2.microsoft.com/en-us/library/ms682429.aspx:

    dwCreationFlags:
    The flags that control the priority class and the creation of the process. For a list of values, see Process Creation Flags. This parameter also controls the new process's priority class, which is used to determine the scheduling priorities of the process's threads. For a list of values, see GetPriorityClass. If none of the priority class flags is specified, the priority class defaults to NORMAL_PRIORITY_CLASS unless the priority class of the creating process is IDLE_PRIORITY_CLASS or BELOW_NORMAL_PRIORITY_CLASS. In this case, the child process receives the default priority class of the calling process.

     

    About StartupInfo structure in MSDN document from http://msdn2.microsoft.com/en-us/library/ms686331.aspx, I only find it is a structure to specify the window station, desktop, standard handles, and appearance of the main window for a process at creation time, but not find it has ShowWindow property. Where did you get this code lines?

    StartupInfo si = new StartupInfo();

    --> si.showWindow = "false";

     

    Hope this helps,

    Regards,

    Wednesday, November 28, 2007 9:06 AM
  • Got it Cheng;

     

    >>Where did you get this code lines?

    I found it somewhere online.After i played arount it but i didnt success.

     

    >>I only find it is a structure to specify the window station, desktop

     

    Now my process is getting created but i think because of this property i am getting some unexpected output. Could you tell me what is all about window stattion and desktop? How would i found it to make it work for me?

     

    I added below line to my code but if i create process notepad.exe some disasterous output is comming.so i think it is a problem with this property only.

     

    startupInfo.desktop = "WinSta0\\Default";

     

    I am using XP.

     

    Thanks,

    Paesh

    Wednesday, November 28, 2007 9:44 AM
  • Hi Paresh,

     

    Never mind about windows stattion and desktop and there is no desktop property in the StartupInfo structure. So you can't write code like this - startupInfo.desktop = "WinSta0\\Default"

    Note that StartupInfo is just a structure defined as follows:

    typedef struct _STARTUPINFO {
      DWORD cb;
      LPTSTR lpReserved;
      LPTSTR lpDesktop;
      LPTSTR lpTitle;
      DWORD dwX;
      DWORD dwY;
      DWORD dwXSize;
      DWORD dwYSize;
      DWORD dwXCountChars;
      DWORD dwYCountChars;
      DWORD dwFillAttribute;
      DWORD dwFlags;
      WORD wShowWindow;
      WORD cbReserved2;
      LPBYTE lpReserved2;
      HANDLE hStdInput;
      HANDLE hStdOutput;
      HANDLE hStdError;
    }

     

    You can pass an instance of StartupInfo as a parameter to the CreateProcessAsUser function. Try to check out an example from here - http://msdn2.microsoft.com/en-us/library/ms682512.aspx

     

    Hope this helps,

    Regards,

     

    Wednesday, November 28, 2007 10:04 AM
  • Hi Cheng;

     

    I am aware of StartupInfo structure. See the declaration of my StartupInfo structure. so i think i can write startupInfo.desktop = "WinSta0\\Default"

     

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]

    public struct StartupInfo

    {

    public int cb;

    public String reserved;

    public String desktop;

    public String title;

    public int x;

    public int y;

    public int xSize;

    public int ySize;

    public int xCountChars;

    public int yCountChars;

    public int fillAttribute;

    public int flags;

    public UInt16 showWindow;

    public UInt16 reserved2;

    public byte reserved3;

    public IntPtr stdInput;

    public IntPtr stdOutput;

    public IntPtr stdError;

    }

     

    My question is: What can be the value of startupInfo.desktop ? Whatever i have given is it fixed or may vary from machine to machine?

     

    Thanks and Regards,

    Paresh

    Wednesday, November 28, 2007 10:11 AM
  • Hi Paresh,

     

    If you have a STARTUPINFO declaration in C# with a public field named desktop, I think you can write this code line  - "startupInfo.desktop = "WinSta0\\Default";"

     

    Remarks on the lpDesktop as follows:

    The name of the desktop, or the name of both the desktop and window station for this process. A backslash in the string indicates that the string includes both the desktop and window station names. For more information, see Thread Connection to a Desktop.

    Windows Me/98/95:  Desktops and window stations are not supported.

     

    As far as I know, the "Default" application desktop will be used by all the processes for which "Winsta0\default" is specified in the STARTUPINFO.lpDesktop structure member. When the lpDesktop structure member is NULL, the window station and desktop is inherited from the parent process. All services that are executed under the LocalSystem account with the Allow Service to Interact with Desktop startup option selected will use "Winsta0\Default". All these processes will share the same desktop heap associated with the "Default" application desktop.

     

    As I understand, I think you can change the value of the lpdesktop in the STARTUPINFO structure from machine to machine. For example, you can change its value as "startUpInfo.lpDesktop = CurrentDesktopName;" or "startUpInfo.lpDesktop = null;"

     

    Hope this helps,

    Regards,

    Thursday, November 29, 2007 2:43 AM
  • Hey Cheng,

     

    I came to know about this things that only system account can have interactive window station and other than system account all account has non-interactive window station.

     

    I think this is the reason why i this problem is occuring. Could you suggest me here something?

     

    Thanks,

    Paresh

     

    Thursday, November 29, 2007 8:20 AM
  • Hi Paresh,

     

    To the extent scope of my knowledge, if you don't use system account, I don't think you are allowed to Interact with Desktop or windows station. I can't give you further helps about this issue. Maybe this is related to the windows OS.

     

    Regards,

    Thursday, November 29, 2007 9:32 AM
  • Ok Cheng,

     

    I found that we can GetWindowStation and SetWindowStation functions are there. Could you tell me in brief is it possible to create interactive window through these function or any other way?

     

    Thanks,

    Paresh

     

    Thursday, November 29, 2007 1:28 PM
  • Hi Paresh,

     

    I did some research from the websites and didn't find anything about GetWindowStation and SetWindowStation functions except this blog - http://blog.vyvojar.cz/jachymko/default.aspx. Some sample codes from this blog as follows:

    Code Block

    public sealed class WindowStation : NamedNativeObject<SafeWindowStationHandle>
    {
        private const string Winsta0 = "Winsta0";

        private WindowStation(string name, SafeWindowStationHandle handle) : base (name, handle)
        {
        }

        public static WindowStation GetCurrent()
        {
            return new WindowStation(Winsta0, SafeNativeMethods.GetProcessWindowStation());
        }

        public static WindowStation GetWindowStation(string name)
        {
            return new WindowStation(name, OpenWindowStationRead(name));
        }

        private static SafeWindowStationHandle OpenWindowStationRead(string name)
        {
            return SafeNativeMethods.OpenWindowStation(name, false, GenericAccessMask.GenericRead);
        }
    }

     

    1)Search GetWindowStation - http://search.msdn.microsoft.com/search/Default.aspx?brand=msdn&query=GetWindowStation&

    2)Search SetWindowStation - http://search.msdn.microsoft.com/search/Default.aspx?brand=msdn&query=SetWindowStation

     

    Could you please clarify where you get these two functions - GetWindowStation and SetWindowStation? Thanks.

     

    Regards,

     

    This response contains links reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.
    Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Friday, November 30, 2007 1:59 AM
  • Cheng,

     

    That were not exact functions but i meant to say we can Get and Set window station. The exact functions are GetProcessWindowStation and SetProcessWindowStation.

     

    Thanks,

    Paresh

    Friday, November 30, 2007 5:22 AM
  • Hi Paresh,

     

    GetProcessWindowStation is used to retrieve a handle to the current window station for the calling process, while SetProcessWindowStation is used to assign the specified window station to the calling process. This enables the process to access objects in the window station such as desktops, the clipboard, and global atoms. I'm not sure if this works for you, as I understand, you can try it. If you get any issues when trying this, please post back to me. Thanks.

     

    Regards,

     

    Friday, November 30, 2007 8:38 AM