Windows get window information

GetWindow function (winuser.h)

Retrieves a handle to a window that has the specified relationship (Z-Order or owner) to the specified window.

Syntax

Parameters

A handle to a window. The window handle retrieved is relative to this window, based on the value of the uCmd parameter.

The relationship between the specified window and the window whose handle is to be retrieved. This parameter can be one of the following values.

Value Meaning
GW_CHILD 5 The retrieved handle identifies the child window at the top of the Z order, if the specified window is a parent window; otherwise, the retrieved handle is NULL. The function examines only child windows of the specified window. It does not examine descendant windows.
GW_ENABLEDPOPUP 6 The retrieved handle identifies the enabled popup window owned by the specified window (the search uses the first such window found using GW_HWNDNEXT); otherwise, if there are no enabled popup windows, the retrieved handle is that of the specified window.
GW_HWNDFIRST 0 The retrieved handle identifies the window of the same type that is highest in the Z order.

If the specified window is a topmost window, the handle identifies a topmost window. If the specified window is a top-level window, the handle identifies a top-level window. If the specified window is a child window, the handle identifies a sibling window.

GW_HWNDLAST 1 The retrieved handle identifies the window of the same type that is lowest in the Z order.

If the specified window is a topmost window, the handle identifies a topmost window. If the specified window is a top-level window, the handle identifies a top-level window. If the specified window is a child window, the handle identifies a sibling window.

GW_HWNDNEXT 2 The retrieved handle identifies the window below the specified window in the Z order.

If the specified window is a topmost window, the handle identifies a topmost window. If the specified window is a top-level window, the handle identifies a top-level window. If the specified window is a child window, the handle identifies a sibling window.

GW_HWNDPREV 3 The retrieved handle identifies the window above the specified window in the Z order.

If the specified window is a topmost window, the handle identifies a topmost window. If the specified window is a top-level window, the handle identifies a top-level window. If the specified window is a child window, the handle identifies a sibling window.

GW_OWNER 4 The retrieved handle identifies the specified window’s owner window, if any. For more information, see Owned Windows.

Return value

If the function succeeds, the return value is a window handle. If no window exists with the specified relationship to the specified window, the return value is NULL. To get extended error information, call GetLastError.

Remarks

The EnumChildWindows function is more reliable than calling GetWindow in a loop. An application that calls GetWindow to perform this task risks being caught in an infinite loop or referencing a handle to a window that has been destroyed.

GetWindowsDirectoryA function (sysinfoapi.h)

Retrieves the path of the Windows directory.

This function is provided primarily for compatibility with legacy applications. New applications should store code in the Program Files folder and persistent data in the Application Data folder in the user’s profile. For more information, see ShGetFolderPath.

Syntax

Parameters

A pointer to a buffer that receives the path. This path does not end with a backslash unless the Windows directory is the root directory. For example, if the Windows directory is named Windows on drive C, the path of the Windows directory retrieved by this function is C:\Windows. If the system was installed in the root directory of drive C, the path retrieved is C:.

The maximum size of the buffer specified by the lpBuffer parameter, in TCHARs. This value should be set to MAX_PATH.

Return value

If the function succeeds, the return value is the length of the string copied to the buffer, in TCHARs, not including the terminating null character.

If the length is greater than the size of the buffer, the return value is the size of the buffer required to hold the path.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The Windows directory is the directory where some legacy applications store initialization and help files. New applications should not store files in the Windows directory; instead, they should store system-wide data in the application’s installation directory, and user-specific data in the user’s profile.

If the user is running a shared version of the system, the Windows directory is guaranteed to be private for each user.

If an application creates other files that it wants to store on a per-user basis, it should place them in the directory specified by the HOMEPATH environment variable. This directory will be different for each user, if so specified by an administrator, through the User Manager administrative tool. HOMEPATH always specifies either the user’s home directory, which is guaranteed to be private for each user, or a default directory (for example, C:\USERS\DEFAULT) where the user will have all access.

Terminal Services:В В If the application is running in a Terminal Services environment, each user has a private Windows directory. There is also a shared Windows directory for the system. If the application is Terminal-Services-aware (has the IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE flag set in the image header), this function returns the path of the system Windows directory, just as the GetSystemWindowsDirectory function does. Otherwise, it retrieves the path of the private Windows directory for the user.

Examples

The sysinfoapi.h header defines GetWindowsDirectory as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.

Get-Windows Edition

Gets edition information about a Windows image.

Syntax

Description

The Get-WindowsEdition cmdlet gets the current editions of the specified Windows image.

The Target parameter gets the target editions available in the specified Windows image.

Use the Online parameter to specify the running operating system on your local computer, or use the Path parameter to specify the location of a mounted Windows image.

Examples

Example 1: Display the current edition of the operating system

This command displays the name of the current edition of the running Windows operating system.

Example 2: Display the target editions for a mounted image

This command displays the names of the available target editions that the mounted Windows image at c:\offline can be changed to.

Parameters

Specifies the maximum output level shown in the logs. The default log level is 3. The accepted values are as follows:

  • 1 = Errors only
  • 2 = Errors and warnings
  • 3 = Errors, warnings, and information
  • 4 = All of the information listed previously, plus debug output
Type: LogLevel
Aliases: LL
Accepted values: Errors, Warnings, WarningsInfo
Position: Named
Default value: None
Accept pipeline input: True
Accept wildcard characters: False

Specifies the full path and file name to log to. If not set, the default is %WINDIR%\Logs\Dism\dism.log . In Windows PE, the default directory is the RAMDISK scratch space which can be as low as 32 MB. The log file will automatically be archived. The archived log file will be saved with .bak appended to the file name and a new log file will be generated. Each time the log file is archived the .bak file will be overwritten. When using a network share that is not joined to a domain, use the net use command together with domain credentials to set access permissions before you set the log path for the DISM log.

Type: String
Aliases: LP
Position: Named
Default value: None
Accept pipeline input: True
Accept wildcard characters: False

Specifies that the action is to be taken on the operating system that is currently running on the local computer.

Type: SwitchParameter
Position: Named
Default value: None
Accept pipeline input: True
Accept wildcard characters: False

Specifies the full path to the root directory of the offline Windows image that you will service. If the directory named Windows is not a subdirectory of the root directory, WindowsDirectory must be specified.

Type: String
Position: Named
Default value: None
Accept pipeline input: True
Accept wildcard characters: False

Specifies a temporary directory that will be used when extracting files for use during servicing. The directory must exist locally. If not specified, the \Windows\%Temp% directory will be used, with a subdirectory name of a randomly generated hexadecimal value for each run of DISM. Items in the scratch directory are deleted after each operation. You should not use a network share location as a scratch directory to expand a package (.cab or .msu file) for installation. The directory used for extracting files for temporary usage during servicing should be a local directory.

Type: String
Position: Named
Default value: None
Accept pipeline input: True
Accept wildcard characters: False

Specifies the path to the location of the BootMgr files. This is necessary only when the BootMgr files are located on a partition other than the one that you are running the command from. Use -SystemDrive to service an installed Windows image from a Windows PE environment.

Type: String
Position: Named
Default value: None
Accept pipeline input: True
Accept wildcard characters: False

Displays a list of Windows editions that an image can be changed to.

Type: SwitchParameter
Position: Named
Default value: None
Accept pipeline input: True
Accept wildcard characters: False

Specifies the path to the Windows directory relative to the image path. This cannot be the full path to the Windows directory; it should be a relative path. If not specified, the default is the Windows directory in the root of the offline image directory.

Get pc (system) information on windows machine

Is there a way to get the following information by using c# script.

PC Name Service Tag CPU type CPU speed size of the c:\ drive, Installed RAM, OS name, OS Product Key, Office Version, and Office Product Key.

5 Answers 5

WMI is what you’re looking for.

Let me add the link to Part 3 too, which concentrates on hardware via WMI

MSDN is also a great resource for WMI scopes.

You have PC Name as a value you want, so you can get this from Environment.MachineName if you want the local computer, or you can do IPHostEntry hostEntry = Dns.GetHostEntry(ip); then string host = hostEntry.HostName; to use DNS to resolve a remote computer’s name if you only have its IP.

You can get certain information from the registry, after you check that Remote Registry is running, assuming you want a remote computer:

And you can start it if found stopped:

Add this using statement to the top of your page:

For the Computer name, you can go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName:

For any local registry commands, just remove RegistryKey.OpenRemoteBaseKey( and , computer) — it becomes:

The RegistryView.Registry64 is usually not required (you can use RegistryView.Default instead), but can be necessary if building a 32-bit app that needs to reach into a registry on a 64-bit OS. Instead of all in one line, you could also do something like this, for example:

For the CPU name:

For the OS Name and key:

From Geeks With Blogs for getting product keys:

That gets the hard ones out of the way. Point is, the registry is your friend.

Get-Windows Image

Gets information about a Windows image in a WIM or VHD file.

Syntax

Description

The Get-WindowsImage cmdlet gets information about a Windows image in a WIM or VHD file.

Use the Mounted parameter to get information about any Windows images that are mapped to directories on the local computer.

Use the ImagePath parameter to get information about images in a specific WIM or VHD file.

Use the Index or Name parameter to get detailed information about a specific image in a WIM or VHD file. For a VHD file, the Index must be 1.

Examples

Example 1: Get information about all mounted images

This command gets information, including mount path, about all of the Windows images mounted on the local computer.

Example 2: Get information about a specific mounted image

This command gets detailed information about the Windows image named «Ultimate» in the install.wim file at c:\imagestore.

Example 3: Get information about a specific image

This command gets basic information about the Windows image in the install.vhd file at c:\imagestore.

Parameters

Specifies the location of a WIM or VHD file.

Type: String
Position: Named
Default value: None
Accept pipeline input: True
Accept wildcard characters: False

Specifies the index number of a Windows image in a WIM or VHD file. For a VHD file, the Index must be 1.

Type: UInt32
Position: Named
Default value: None
Accept pipeline input: True
Accept wildcard characters: False

Specifies the maximum output level shown in the logs. The default log level is 3. The accepted values are as follows:

  • 1 = Errors only
  • 2 = Errors and warnings
  • 3 = Errors, warnings, and information
  • 4 = All of the information listed previously, plus debug output
Type: LogLevel
Aliases: LL
Accepted values: Errors, Warnings, WarningsInfo
Position: Named
Default value: None
Accept pipeline input: True
Accept wildcard characters: False

Specifies the full path and file name to log to. If not set, the default is %WINDIR%\Logs\Dism\dism.log . In Windows PE, the default directory is the RAMDISK scratch space which can be as low as 32 MB. The log file will automatically be archived. The archived log file will be saved with .bak appended to the file name and a new log file will be generated. Each time the log file is archived the .bak file will be overwritten. When using a network share that is not joined to a domain, use the net use command together with domain credentials to set access permissions before you set the log path for the DISM log.

Type: String
Aliases: LP
Position: Named
Default value: None
Accept pipeline input: True
Accept wildcard characters: False

Gets information, including the mount path, for all images mapped to a directories on the local computer.

Type: SwitchParameter
Position: Named
Default value: None
Accept pipeline input: True
Accept wildcard characters: False

Specifies the name of an image in a WIM or VHD file.

Type: String
Position: Named
Default value: None
Accept pipeline input: True
Accept wildcard characters: False

Specifies a temporary directory that will be used when extracting files for use during servicing. The directory must exist locally. If not specified, the \Windows\%Temp% directory will be used, with a subdirectory name of a randomly generated hexadecimal value for each run of DISM. Items in the scratch directory are deleted after each operation. You should not use a network share location as a scratch directory to expand a package (.cab or .msu file) for installation. The directory used for extracting files for temporary usage during servicing should be a local directory.

Читайте также:  Windows 10 не видит дискретную видеокарту amd
Оцените статью