@@ -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
$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
$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