/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" convert images in MSH "," Style Problems "," ColorCoding MSH scripts on blog "," GUI folder copy tool "," MSHObjectViewer mentioned in More talking about Mo... "," MSH registry access "," Unix => MSH Translations: find and grep "," MSH Object Viewer "," Windows "Monad" Shell Beta 2 Documentation Pack "," sample of mine used at reskit.net "," ")

Friday, October 21, 2005

 


StartRDP script



A MSH script to connect to a client with "remote Desktop" even if RDP is not enabled,
if its not enabled then the script will enable it and it will be disabled again after RDP session closes.

I did remote registry access in MSH witch the .NET class.
don't know how to do a remote registry in "Native" MSH

gr /\/\o\/\/
# StartRDP.msh
# /\/\o\/\/ 2005
# Script to connect to RDP client even if RDP is not enabled
# if RDP was disabled the script will disable RDP again after session.

Function StartRdp {

$MachineName = $Args[0]

$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $MachineName)

# $True makes regKey writable
$regKey= $regKey.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Terminal Server" ,$True)

# the Setting is Deny so I reverse it first with ! to set $RDPenabled
$RDPEnabled = !([system.boolean]$regkey.getvalue('fDenyTSConnections'))

write-host "$MachineName RDP = $RDPEnabled"
If (!$RDPEnabled) {
$regkey.SetValue('fDenyTSConnections',0)
#write changes without closing key
$regKey.flush()
write-Host "enabled RDP on $MachineName"
}
sleep 1
"Starting the remote Desktop Connection"
cmd /c mstsc /v: $MachineName

#If changed set the Key back to original value :
if (!$RDPEnabled) {
$regkey.SetValue('fDenyTSConnections',[int]!$RDPEnabled);
write-Host "Disabled RDP again on $MachineName"
}

#Close the Reg Key
$regKey.Close()
}



Comments:
Blogger Paul Adams
This comment has been removed by a blog administrator.
 
Post a Comment

Links to this post:

Create a Link



<< Home

Archives

October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Google
 
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?