Saturday, March 22, 2014

How to acquire a list of special folders

If you were wondering how to acquire a list of special folders, this is an easy way of doing it:

$ws = new-object -comobject wscript.shell
$rt = $ws.SpecialFolders

When you type $rt on the next line:

$rt
And press enter, Powershell will display a list of special folders like this:

C:\Users\Public\Desktop
C:\ProgramData\Microsoft\Windows\Start Menu
C:\ProgramData\Microsoft\Windows\Start Menu\Programs
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
C:\Users\Administrator\Desktop
C:\Users\Administrator\AppData\Roaming
C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Printer Shortcuts
C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Templates
C:\Windows\Fonts
C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Network Shortcuts
C:\Users\Administrator\Desktop
C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu
C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\SendTo
C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Recent
C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Star
C:\Users\Administrator\Favorites
C:\Users\Administrator\Documents
C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs

Suppose you knew that the special folder for fonts would always be the 9th one -- it is zero based:








$rt.Item(8)
C:\Windows\Fonts

Friday, March 21, 2014

Building Shortcut Scripts Through Automation

Due to popular demand for information on how to create shortcut scripts, I'm wondering if anyone would be interested in a tool that would help you do this?

Please reply if you are interested.

Here's a screenshot of the tool:





Here's the results:


Wednesday, March 19, 2014

How To Run Control Panel Wizzards Using Powershell

Here's a link to a site that shows how to do these using VB6:

http://vbnet.mvps.org/index.html?code/system/controlpnl.htm

To accomplish the same in Powershell, simply copy the command line parameters:

rundll32.exe shell32.dll,Control_RunDLL appwiz.cpl,,1

And then place quotes around it as shown below:

$ws = new-object -comobject wscript.shell
$ws.Run("rundll32.exe shell32.dll,Control_RunDLL appwiz.cpl,,1")

Thursday, March 13, 2014

Powershell: How to create an Inputbox

Here's how you can create an InputBox in Powershell:

$Iret = [reflection.assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
$Answer = [Microsoft.VisualBasic.Interaction]::InputBox("Please Enter a language", "Language Selection", "C#")

Powershell: Using Visual Basic's CreateObject

Here's how you can use CreateObject in Powershell:

$Iret = [reflection.assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
$Iret = [Microsoft.VisualBasic.Interaction]::CreateObject("ADODB.Connection")

How To Create A msgbox in Powershell

One of the rather charming features of Powershell is its ability to enable you to use other existing .Net framework languages. I like it because it makes you feel like you aren't giving up on what you already know.

Such is the case with the Msgbox:

$Iret = [reflection.assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
$Iret = [Microsoft.VisualBasic.Interaction]::MsgBox("This works just fine")

How To Create A Messagebox In Powershell

Here's how to create a Messagebox:

$Iret = [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$Iret = [System.Windows.Forms.MessageBox]::Show("Hello World")

There you go.