Sign in
|
Join PowerShell.com!
|
Help
Home
PowerTips
Ask the Experts
Forums
Webcasts
Blogs
eBookV2
Script Library
Twitter Grid
Modules
QuickClick
Scripts
Snippets
Videos
Library
»
Script Library
»
Remoting
»
Slideshow
Remoting Slideshow
Share
|
Browse Library
Module Library
QuickClick Library
Script Library
Active Directory
BizTalk
Citrix
Clustering
Desktop
Exchange Server 2003
Exchange Server 2007
File System
Group Policy
Internet Information Server (IIS)
Local Accounts
Logs
Microsoft Office
Microsoft Team Foundation Server
MySQL
Networking
Registry
Remote Desktop Services
Remoting
Security
SharePoint
SQL Server
System Center Virtual Machine Manager
System Center Configuration Manager
System Center Operations Manager
Tutorial
Terminal Server
Using .Net
Virtual Server
VMware
Windows 7
Windows HPC
Windows Server 2000
Windows Server 2003
Windows Server 2008
Windows XP
WMI
Misc
Snippet Library
Video Library
Members Only
Tags
Powershell
Runas
User Elevation
View more
RunAs V2
##########################
#Coded by Felipe Binotto##
##########################
function
Return-DropDown
([
Object
]
$DropDown
){
$Choice
=
$DropDown
.
SelectedItem.ToString
()
$user
=
$user
.
Text
foreach
(
$Item
in
$xml
.
Items.Item
){
if
(
$Item
.
app
-eq
$Choice
){
if
(
$Item
.
path.split
(
"."
)[
-
1]
-eq
"msc"
){
.\psexec
-e
-d
-u
$user
-p
$password
.
Text
mmc
"$($Item.path)"
}
elseif
(
$Item
.
arguments
){
.\psexec
-e
-d
-u
$user
-p
$password
.
Text
$Item
.
path
$Item
.
arguments
}
else
{.\psexec
-e
-d
-u
$user
-p
$password
.
Text
$Item
.
path
}}
}
}
function
Add-App
(){
Get-Name
if
(
$script:check
){
$objForm
=
New-Object
System.Windows.Forms.OpenFileDialog
$objForm
.
InitialDirectory
=
"C:\"
$objForm
.
Filter
=
"All Files (*.*)|*.*"
$objForm
.
Title
=
"Source"
$objForm
.
ShowHelp
=
$true
$show
=
$objForm
.
ShowDialog
()
if
(
$show
.
value__
-eq
1){
Get-Arguments
$path
=
$objForm
.
FileName
$item
=
$xml
.
CreateElement
(
"item"
)
$Item
.
SetAttribute
(
"App"
,
$script:app
)
$Item
.
SetAttribute
(
"Path"
,
$path
)
$Item
.
SetAttribute
(
"Arguments"
,
$script:arg
)
$item
.
set_InnerText
(
$app
)
$xml
.
get_DocumentElement
().
AppendChild
(
$item
)
$xml
|
Export-Clixml
apps.
xml
$DropDown
.
Items.Add
(
$Item
.
app
) |
Out-Null
}}}
function
Remove-App
(){
for(
$i
=
0;
$i
-lt
$xml
.
Items.Item.Count
;
$i
++
){
if
(
$xml
.
Items.Item
[
$i
].
App
-eq
$DropDown
.
SelectedItem.ToString
()){
$DropDown
.
Items.Remove
(
$xml
.
Items.Item
[
$i
].
app
)
$xml
.
Items.RemoveChild
(
$xml
.
Items.item
[
$i
])
$xml
|
Export-Clixml
apps.
xml
}
}}
Function
Get-Name
(){
$Form
=
New-Object
System.Windows.Forms.Form
$Form
.
width
=
200
$Form
.
height
=
90
$Form
.
startposition
=
"centerscreen"
$Form
.
Text
=
"App's Name"
$arg
=
new-object
System.Windows.Forms.TextBox
$arg
.
Location
=
new-object
System.Drawing.Size
(10,5)
$arg
.
Size
=
new-object
System.Drawing.Size
(170,20)
$OKButton
=
new-object
System.Windows.Forms.Button
$OKButton
.
Text
=
"OK"
$OKButton
.
Add_Click
({
$script:app
=
$arg
.
Text
;
$script:check
=
$true
;
$Form
.
Close
()})
$OKButton
.
Location
=
new-object
System.Drawing.Size
(50,35)
$OKButton
.
Size
=
new-object
System.Drawing.Size
(40,20)
$CButton
=
new-object
System.Windows.Forms.Button
$CButton
.
Text
=
"CANCEL"
$CButton
.
Location
=
new-object
System.Drawing.Size
(95,35)
$CButton
.
Size
=
new-object
System.Drawing.Size
(70,20)
$CButton
.
Add_Click
({
$script:check
=
$false
;
$Form
.
Close
()})
$Form
.
Controls.Add
(
$CButton
)
$Form
.
Controls.Add
(
$arg
)
$Form
.
Controls.Add
(
$arglabel
)
$Form
.
Controls.Add
(
$OKButton
)
$Form
.
Add_Shown
({
$Form
.
Activate
()})
$Form
.
ShowDialog
()}
Function
Get-Arguments
(){
$Form
=
New-Object
System.Windows.Forms.Form
$Form
.
width
=
200
$Form
.
height
=
90
$Form
.
startposition
=
"centerscreen"
$Form
.
Text
=
"Arguments"
$arg
=
new-object
System.Windows.Forms.TextBox
$arg
.
Location
=
new-object
System.Drawing.Size
(10,5)
$arg
.
Size
=
new-object
System.Drawing.Size
(170,20)
$OKButton
=
new-object
System.Windows.Forms.Button
$OKButton
.
Text
=
"OK"
$OKButton
.
Add_Click
({
$script:arg
=
$arg
.
Text
;
$Form
.
Close
()})
$OKButton
.
Location
=
new-object
System.Drawing.Size
(50,35)
$OKButton
.
Size
=
new-object
System.Drawing.Size
(40,20)
$NOButton
=
new-object
System.Windows.Forms.Button
$NOButton
.
Text
=
"NO"
$NOButton
.
Location
=
new-object
System.Drawing.Size
(95,35)
$NOButton
.
Size
=
new-object
System.Drawing.Size
(40,20)
$NOButton
.
Add_Click
({
$Form
.
Close
()})
$Form
.
Controls.Add
(
$NOButton
)
$Form
.
Controls.Add
(
$arg
)
$Form
.
Controls.Add
(
$OKButton
)
$Form
.
Add_Shown
({
$Form
.
Activate
()})
$Form
.
ShowDialog
()}
Function
Main(){
[
System.Reflection.Assembly
]::
LoadWithPartialName
(
"System.Windows.Forms"
) |
Out-Null
[
System.Reflection.Assembly
]::
LoadWithPartialName
(
"System.Drawing"
) |
Out-Null
if
(
Test-Path
apps.
xml
){
$xml
=
Import-Clixml
apps.
xml
}
else
{
$xml
=
@
'
<items><item App="CMD" Path="C:\Windows\System32\cmd.exe" Arguments="">CMD</item></items>
'
@ |
Out-File
apps.
xml
$xml
=
[
xml
](
Get-Content
apps.
xml
)}
$Form
=
New-Object
System.Windows.Forms.Form
$Form
.
width
=
300
$Form
.
height
=
255
$Form
.
Text
=
"Run As"
$Form
.
backcolor
=
"black"
$Form
.
maximumsize
=
New-Object
System.Drawing.Size
(300,250)
$Form
.
startposition
=
"centerscreen"
$Form
.
KeyPreview
=
$True
$Form
.
Add_KeyDown
({
if
(
$_
.
KeyCode
-eq
"Enter"
)
{Try{
Return-DropDown
(
$DropDown
)}Catch{[
Windows.Forms.MessageBox
]::
Show
(
"Select one of the options from the DropBox."
)}}})
$Form
.
Add_KeyDown
({
if
(
$_
.
KeyCode
-eq
"Escape"
)
{
$Form
.
Close
()}})
$DropDown
=
new-object
System.Windows.Forms.ComboBox
$DropDown
.
Location
=
new-object
System.Drawing.Size
(60,100)
$DropDown
.
Size
=
new-object
System.Drawing.Size
(180,30)
$DropDownArrayList
=
New-Object
System.Collections.ArrayList
foreach
(
$Item
in
$xml
.
Items.Item
){
$DropDownArrayList
.
add
(
$Item
.
App
) |
Out-Null
}
$DropDownArrayList
.
sort
()
ForEach
(
$Item
in
$DropDownArrayList
) {
$DropDown
.
Items.Add
(
$Item
) |
Out-Null
}
$RunButton
=
new-object
System.Windows.Forms.Button
$RunButton
.
Location
=
new-object
System.Drawing.Size
(100,140)
$RunButton
.
Size
=
new-object
System.Drawing.Size
(100,20)
$RunButton
.
BackColor
=
"Transparent"
$RunButton
.
Text
=
"OK"
$RunButton
.
ForeColor
=
"White"
$RunButton
.
Add_Click
({Try{
Return-DropDown
(
$DropDown
)}Catch{[
Windows.Forms.MessageBox
]::
Show
(
"Select one of the options from the DropBox."
)}})
$AddButton
=
new-object
System.Windows.Forms.Button
$AddButton
.
Location
=
new-object
System.Drawing.Size
(5,190)
$AddButton
.
Size
=
new-object
System.Drawing.Size
(20,20)
$AddButton
.
BackColor
=
"Transparent"
$AddButton
.
Text
=
"+"
$AddButton
.
Font
=
New-Object
System.Drawing.Font
(
"Microsoft Sans Serif"
,20,5,0,0)
$AddButton
.
ForeColor
=
"White"
$AddButton
.
Add_Click
({
Add-App
})
$RemoveButton
=
new-object
System.Windows.Forms.Button
$RemoveButton
.
Location
=
new-object
System.Drawing.Size
(26,190)
$RemoveButton
.
Size
=
new-object
System.Drawing.Size
(20,20)
$RemoveButton
.
BackColor
=
"Transparent"
$RemoveButton
.
Text
=
"-"
$RemoveButton
.
Font
=
New-Object
System.Drawing.Font
(
"Microsoft Sans Serif"
,20,5,0,0)
$RemoveButton
.
ForeColor
=
"White"
$RemoveButton
.
Add_Click
({
Remove-App
})
$LockButton
=
new-object
System.Windows.Forms.Button
$LockButton
.
Location
=
new-object
System.Drawing.Size
(47,190)
$LockButton
.
Size
=
new-object
System.Drawing.Size
(70,20)
$LockButton
.
BackColor
=
"Transparent"
$LockButton
.
Text
=
"LOCK"
$LockButton
.
Font
=
New-Object
System.Drawing.Font
(
"Microsoft Sans Serif"
,14,5,0,0)
$LockButton
.
ForeColor
=
"White"
$LockButton
.
Add_Click
({
rundll32.exe
user32.dll
, LockWorkStation})
$user
=
new-object
System.Windows.Forms.TextBox
$user
.
Location
=
new-object
System.Drawing.Size
(100,10)
$user
.
Size
=
new-object
System.Drawing.Size
(150,20)
$userLabel
=
new-object
System.Windows.Forms.Label
$userLabel
.
Location
=
new-object
System.Drawing.Size
(10,10)
$userLabel
.
size
=
new-object
System.Drawing.Size
(200,30)
$userLabel
.
backcolor
=
"Transparent"
$userLabel
.
forecolor
=
"white"
$userLabel
.
Font
=
new-object
System.Drawing.Font
(
"Microsoft Sans Serif"
,12,[
System.Drawing.FontStyle
]::
Bold
)
$userLabel
.
Text
=
"Username"
$password
=
new-object
System.Windows.Forms.TextBox
$password
.
Location
=
new-object
System.Drawing.Size
(100,50)
$password
.
UseSystemPasswordChar
=
$true
$password
.
Size
=
new-object
System.Drawing.Size
(150,50)
$passwordLabel
=
new-object
System.Windows.Forms.Label
$passwordLabel
.
Location
=
new-object
System.Drawing.Size
(10,50)
$passwordLabel
.
size
=
new-object
System.Drawing.Size
(150,30)
$passwordLabel
.
backcolor
=
"Transparent"
$passwordLabel
.
forecolor
=
"white"
$passwordLabel
.
Font
=
new-object
System.Drawing.Font
(
"Microsoft Sans Serif"
,12,[
System.Drawing.FontStyle
]::
Bold
)
$passwordLabel
.
Text
=
"Password"
$Form
.
Controls.Add
(
$user
)
$Form
.
Controls.Add
(
$userLabel
)
$Form
.
Controls.Add
(
$password
)
$Form
.
Controls.Add
(
$passwordLabel
)
$Form
.
Controls.Add
(
$DropDown
)
$Form
.
Controls.Add
(
$RunButton
)
$Form
.
Controls.Add
(
$RemoveButton
)
$Form
.
Controls.Add
(
$AddButton
)
$Form
.
Controls.Add
(
$LockButton
)
$Form
.
Add_Shown
({
$Form
.
Activate
()})
$Form
.
ShowDialog
()}
Main
Loading...
RunAs V2
Basic Resource...
Basic Resouce...
Remote uninstall...
Remote install...
Daily Disk...
Daily Disk...
View all files
Copyright 2011 PowerShell.com. All rights reserved.