Skip to content

Commit bfdac65

Browse files
committed
Added New-NtWindowStation.
1 parent 0e64054 commit bfdac65

3 files changed

Lines changed: 99 additions & 4 deletions

File tree

NtApiDotNet/NtWindowStation.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,22 @@ public static NtResult<NtWindowStation> Create(ObjectAttributes object_attribute
203203
}
204204
}
205205

206+
/// <summary>
207+
/// Create a Window Station by name.
208+
/// </summary>
209+
/// <param name="object_attributes">Object attributes for the Window Station.</param>
210+
/// <param name="desired_access">Desired access for the Window Station.</param>
211+
/// <param name="kbd_dll_path">Path to Keyboard DLL e.g. kbusa.dll.</param>
212+
/// <param name="keyboard_locale">Locale ID, e.g. 0x4090409.</param>
213+
/// <param name="language_id">Language ID e.g. 0x409.</param>
214+
/// <returns>The Window Station.</returns>
215+
public static NtWindowStation Create(ObjectAttributes object_attributes,
216+
WindowStationAccessRights desired_access, string kbd_dll_path,
217+
int language_id, int keyboard_locale)
218+
{
219+
return Create(object_attributes, desired_access, kbd_dll_path, language_id, keyboard_locale, true).Result;
220+
}
221+
206222
/// <summary>
207223
/// Create a Window Station by name.
208224
/// </summary>

NtObjectManager/NtObjectManager.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ CmdletsToExport = 'Add-NtKey', 'Get-NtDirectory', 'Get-NtEvent', 'Get-NtFile',
102102
'Remove-NtTokenSecurityAttribute', 'Get-AccessibleEventTrace',
103103
'Test-NtToken', 'Get-AccessibleToken', 'Set-NtProcessJob',
104104
'Get-AccessibleWnf', 'Get-AccessibleWindowStation', 'Get-NtProcessJob',
105-
'Get-NtWindowStation', 'Get-NtDesktop'
105+
'Get-NtWindowStation', 'Get-NtDesktop', 'New-NtWindowStation'
106106

107107
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
108108
AliasesToExport = @()

NtObjectManager/NtWin32Cmdlets.cs

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ namespace NtObjectManager
2828
/// </example>
2929
/// <example>
3030
/// <code>$obj = Get-NtWindowStation \Windows\WindowStations\WinSta0</code>
31-
/// <para>Get an Window Station object with an absolute path.</para>
31+
/// <para>Get a Window Station object with an absolute path.</para>
3232
/// </example>
3333
/// <example>
3434
/// <code>$root = Get-NtDirectory \Windows\WindowStations&#x0A;$obj = Get-NtWindowStation ABC -Root $root</code>
35-
/// <para>Get an Window Station object with a relative path.
35+
/// <para>Get a Window Station object with a relative path.
3636
/// </para>
3737
/// </example>
3838
/// <example>
3939
/// <code>$obj = Get-NtWindowStation -Path WinSta0 -Win32Path</code>
40-
/// <para>Get an Window Station object from Win32 path.</para>
40+
/// <para>Get a Window Station object from Win32 path.</para>
4141
/// </example>
4242
/// <para type="link">about_ManagingNtObjectLifetime</para>
4343
[Cmdlet(VerbsCommon.Get, "NtWindowStation", DefaultParameterSetName = "All")]
@@ -220,4 +220,83 @@ protected override void ProcessRecord()
220220
}
221221
}
222222
}
223+
224+
/// <summary>
225+
/// <para type="synopsis">Creates a Window Station object by path.</para>
226+
/// <para type="description">This cmdlet creates an new Window Station object. The absolute path to the object in the NT object manager name space must be specified.
227+
/// It's also possible to create the object relative to an existing object by specified the -Root parameter.</para>
228+
/// </summary>
229+
/// <example>
230+
/// <code>$obj = New-NtWindowStation \Windows\WindowStations\WinSta0</code>
231+
/// <para>Create a Window Station object with an absolute path.</para>
232+
/// </example>
233+
/// <example>
234+
/// <code>$root = Get-NtDirectory \Windows\WindowStations&#x0A;$obj = New-NtWindowStation ABC -Root $root</code>
235+
/// <para>Create a Window Station object with a relative path.
236+
/// </para>
237+
/// </example>
238+
/// <example>
239+
/// <code>$obj = New-NtWindowStation -Path ABC -Win32Path</code>
240+
/// <para>Create a Window Station object from Win32 path.</para>
241+
/// </example>
242+
/// <para type="link">about_ManagingNtObjectLifetime</para>
243+
[Cmdlet(VerbsCommon.New, "NtWindowStation")]
244+
[OutputType(typeof(NtWindowStation))]
245+
public sealed class NewNtWindowStationCmdlet : NtObjectBaseCmdletWithAccess<WindowStationAccessRights>
246+
{
247+
/// <summary>
248+
/// <para type="description">The NT object manager path to the object to use.</para>
249+
/// </summary>
250+
[Parameter(Position = 0, Mandatory = true)]
251+
public override string Path { get; set; }
252+
253+
/// <summary>
254+
/// <para type="description">The DLL containing the Keyboard Layout information.</para>
255+
/// </summary>
256+
[Parameter]
257+
public string KeyboardLayoutDll { get; set; }
258+
259+
/// <summary>
260+
/// <para type="description">The language ID for the keyboard. E.g. 0x409.</para>
261+
/// </summary>
262+
[Parameter]
263+
public int? LanguageId { get; set; }
264+
265+
/// <summary>
266+
/// <para type="description">The keyboard local. E.g. 0x4090409.</para>
267+
/// </summary>
268+
[Parameter]
269+
public int? KeyboardLocale { get; set; }
270+
271+
/// <summary>
272+
/// Determine if the cmdlet can create objects.
273+
/// </summary>
274+
/// <returns>True if objects can be created.</returns>
275+
protected override bool CanCreateDirectories()
276+
{
277+
return true;
278+
}
279+
280+
/// <summary>
281+
/// Get the Win32 path for a specified path.
282+
/// </summary>
283+
/// <param name="path">The path component.</param>
284+
/// <returns>The full NT path.</returns>
285+
protected override string GetWin32Path(string path)
286+
{
287+
return $@"{NtWindowStation.GetWindowStationDirectory()}\{path}";
288+
}
289+
290+
/// <summary>
291+
/// Method to create an object from a set of object attributes.
292+
/// </summary>
293+
/// <param name="obj_attributes">The object attributes to create/open from.</param>
294+
/// <returns>The newly created object.</returns>
295+
protected override object CreateObject(ObjectAttributes obj_attributes)
296+
{
297+
return NtWindowStation.Create(obj_attributes, Access,
298+
KeyboardLayoutDll ?? "kbdus.dll",
299+
LanguageId ?? 0x409, KeyboardLocale ?? 0x4090409);
300+
}
301+
}
223302
}

0 commit comments

Comments
 (0)