{"id":550,"date":"2014-10-27T12:25:20","date_gmt":"2014-10-27T12:25:20","guid":{"rendered":"http:\/\/giraffeit.com\/?p=550"},"modified":"2014-10-27T12:25:20","modified_gmt":"2014-10-27T12:25:20","slug":"citrix","status":"publish","type":"post","link":"https:\/\/giraffeit.com\/index.php\/2014\/10\/27\/citrix\/","title":{"rendered":"Powershell &#8211; logon script based on username"},"content":{"rendered":"<p>Devised this script that will run a program based on the username of the logged in user and resizes the window as needed.<\/p>\n<p>&nbsp;<\/p>\n<p>#find the currently logged on user and stick the name into the $LoggedOnUser variable<br \/>\n$LoggedOnUser=(Get-WmiObject -Class Win32_Process | Where-Object {$_.ProcessName -eq &#8216;explorer.exe&#8217;}).GetOwner() | select User<br \/>\necho $LoggedOnUser<\/p>\n<p>#Uncomment the line below and add into line 2 place if using on a local machine<br \/>\n#$LoggedOnUser=Get-WMIObject -class Win32_ComputerSystem | select username<br \/>\n#if statement now checking who is who.<\/p>\n<p>If ($LoggedOnUser.user -eq &#8220;abc1&#8221;)<br \/>\n{<br \/>\n&amp; &#8220;C:Windowstrace32.exe&#8221;<br \/>\n&amp; &#8220;C:Windowsregedit.exe&#8221;<br \/>\n}<br \/>\nelseif ($LoggedOnUser.user -eq &#8220;abc2&#8221;)<br \/>\n{<br \/>\n&amp; &#8220;C:Windowstrace32.exe&#8221;<br \/>\n&amp; &#8220;C:Windowsregedit.exe&#8221;<br \/>\n}<br \/>\nelseif ($LoggedOnUser.user -eq &#8220;abc3&#8221;)<br \/>\n{<br \/>\n&amp; &#8220;C:Windowstrace32.exe&#8221;<br \/>\n&amp; &#8220;C:Windowsregedit.exe&#8221;<br \/>\n}<br \/>\nelseif ($LoggedOnUser.user -eq &#8220;abc4&#8221;)<br \/>\n{<br \/>\n&amp; &#8220;C:Windowstrace32.exe&#8221;<br \/>\n&amp; &#8220;C:Windowsregedit.exe&#8221;<br \/>\n}<br \/>\nelseif ($LoggedOnUser.user -eq &#8220;abc5&#8221;)<br \/>\n{<br \/>\n&amp; &#8220;C:Windowstrace32.exe&#8221;<br \/>\n&amp; &#8220;C:Windowsregedit.exe&#8221;<br \/>\n}<br \/>\nelseif ($LoggedOnUser.user -eq &#8220;abc6&#8221;)<br \/>\n{<br \/>\n&amp; &#8220;C:Windowstrace32.exe&#8221;<br \/>\n&amp; &#8220;C:Windowsregedit.exe&#8221;<br \/>\n}<br \/>\nelseif ($LoggedOnUser.user -eq &#8220;abc7&#8221;)<br \/>\n{<br \/>\n&amp; &#8220;C:Windowstrace32.exe&#8221;<br \/>\n&amp; &#8220;C:Windowsregedit.exe&#8221;<br \/>\n}<br \/>\nelseif ($LoggedOnUser.user -eq &#8220;abc8&#8221;)<br \/>\n{<br \/>\n&amp; &#8220;C:Windowstrace32.exe&#8221;<br \/>\n&amp; &#8220;C:Windowsregedit.exe&#8221;<br \/>\n}<br \/>\nelseif ($LoggedOnUser.user -eq &#8220;abc9&#8221;)<br \/>\n{<br \/>\n&amp; &#8220;C:Windowstrace32.exe&#8221;<br \/>\n&amp; &#8220;C:Windowsregedit.exe&#8221;<br \/>\n}<br \/>\nelseif ($LoggedOnUser.user -eq &#8220;abc10&#8221;)<br \/>\n{<br \/>\n&amp; &#8220;C:Windowstrace32.exe&#8221;<br \/>\n&amp; &#8220;C:Windowsregedit.exe&#8221;<br \/>\n}<br \/>\nelseif ($LoggedOnUser.user -eq &#8220;abc11&#8221;)<br \/>\n{<br \/>\n&amp; &#8220;C:Windowstrace32.exe&#8221;<br \/>\n&amp; &#8220;C:Windowsregedit.exe&#8221;<br \/>\n}<br \/>\nelseif ($LoggedOnUser.user -eq &#8220;abc12&#8221;)<br \/>\n{<br \/>\n&amp; &#8220;C:Windowstrace32.exe&#8221;<br \/>\n&amp; &#8220;C:Windowsregedit.exe&#8221;<br \/>\n}<br \/>\nelseif ($LoggedOnUser.user -eq &#8220;abc13&#8221;)<br \/>\n{<br \/>\n&amp; &#8220;C:Windowstrace32.exe&#8221;<br \/>\n&amp; &#8220;C:Windowsregedit.exe&#8221;<br \/>\n}<br \/>\nelseif ($LoggedOnUser.user -eq &#8220;abc14&#8221;)<br \/>\n{<br \/>\n&amp; &#8220;C:Windowstrace32.exe&#8221;<br \/>\n&amp; &#8220;C:Windowsregedit.exe&#8221;<br \/>\n}<br \/>\nelseif ($LoggedOnUser.user -eq &#8220;abc15&#8221;)<br \/>\n{<br \/>\n&amp; &#8220;C:Windowstrace32.exe&#8221;<br \/>\n&amp; &#8220;C:Windowsregedit.exe&#8221;<br \/>\n}<br \/>\nelseif ($LoggedOnUser.user -eq &#8220;abc16&#8221;)<br \/>\n{<br \/>\n&amp; &#8220;C:Windowstrace32.exe&#8221;<br \/>\n&amp; &#8220;C:Windowsregedit.exe&#8221;<br \/>\n}<br \/>\nelseif ($LoggedOnUser.user -eq &#8220;abc17&#8221;)<br \/>\n{<br \/>\n&amp; &#8220;C:Windowstrace32.exe&#8221;<br \/>\n&amp; &#8220;C:Windowsregedit.exe&#8221;<br \/>\n}<br \/>\nelseif ($LoggedOnUser.user -eq &#8220;abc18&#8221;)<br \/>\n{<br \/>\n&amp; &#8220;C:Windowstrace32.exe&#8221;<br \/>\n&amp; &#8220;C:Windowsregedit.exe&#8221;<br \/>\n}<br \/>\nelseif ($LoggedOnUser.user -eq &#8220;abcz19&#8221;)<br \/>\n{<br \/>\n&amp; &#8220;C:Windowstrace32.exe&#8221;<br \/>\n&amp; &#8220;C:Windowsregedit.exe&#8221;<br \/>\n}<\/p>\n<p>#final error trap : no username recognised ? Give them a popup box<br \/>\nelse<br \/>\n{<br \/>\n[System.Reflection.Assembly]::LoadWithPartialName(\u201cSystem.Windows.Forms\u201d)<br \/>\n[Windows.Forms.MessageBox]::Show(\u201cThis account has not been assigned a citrix autorun. Now logging off \u201d, \u201cCitrix Presentation\u201d, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)<br \/>\n}<\/p>\n<p>#makes sure the programs are open by delaying the script by 15 seconds<br \/>\nstart-sleep -s 15<br \/>\n#find process now and move it<br \/>\nAdd-Type @&#8221;<br \/>\nusing System;<br \/>\nusing System.Runtime.InteropServices;<\/p>\n<p>public class Win32 {<br \/>\n[DllImport(&#8220;user32.dll&#8221;)]<br \/>\n[return: MarshalAs(UnmanagedType.Bool)]<br \/>\npublic static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);<br \/>\n}<br \/>\n&#8220;@<br \/>\n[int]$X = 960<br \/>\n[int]$Y = 0<br \/>\n[int]$nWidth = 960<br \/>\n[int]$nHeight =1080<br \/>\n[string]$processName = &#8220;proficyclient&#8221;<\/p>\n<p>$handle = (Get-Process | where {$_.ProcessName -eq $processName}).MainWindowHandle<\/p>\n<p>[Win32]::MoveWindow($handle, $X, $Y, $nWidth, $nHeight, $true )<\/p>\n<p>#find second process<br \/>\nAdd-Type @&#8221;<br \/>\nusing System;<br \/>\nusing System.Runtime.InteropServices;<\/p>\n<p>public class Win32 {<br \/>\n[DllImport(&#8220;user32.dll&#8221;)]<br \/>\n[return: MarshalAs(UnmanagedType.Bool)]<br \/>\npublic static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);<br \/>\n}<br \/>\n&#8220;@<br \/>\n[int]$X = 0<br \/>\n[int]$Y = 0<br \/>\n[int]$nWidth = 960<br \/>\n[int]$nHeight =1080<br \/>\n[string]$processName = &#8220;vlc&#8221;<\/p>\n<p>$handle = (Get-Process | where {$_.ProcessName -eq $processName}).MainWindowHandle<\/p>\n<p>[Win32]::MoveWindow($handle, $X, $Y, $nWidth, $nHeight, $true )<\/p>\n<p>$a = new-object -comobject wscript.shell<br \/>\n$b = $a.popup(&#8220;Please wait 15 seconds. This window will dissapear after 15 seconds &#8220;,15,&#8221;Wait&#8221;)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Devised this script that will run a program based on the username of the logged in user and resizes the window as needed. &nbsp; #find the currently logged on user and stick the name into the $LoggedOnUser variable $LoggedOnUser=(Get-WmiObject -Class Win32_Process | Where-Object {$_.ProcessName -eq &#8216;explorer.exe&#8217;}).GetOwner() | select User echo $LoggedOnUser #Uncomment the line below &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/giraffeit.com\/index.php\/2014\/10\/27\/citrix\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Powershell &#8211; logon script based on username&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-550","post","type-post","status-publish","format-standard","hentry","category-bog"],"_links":{"self":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/posts\/550","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/comments?post=550"}],"version-history":[{"count":0,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/posts\/550\/revisions"}],"wp:attachment":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/media?parent=550"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/categories?post=550"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/tags?post=550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}