PowerShell script for toggling network configuration between dynamic and static on Windows 7

Changing network configuration can be a real pain if you use your computer, a notebook for example, in more than one different network where you need a static configuration instead of a dynamic. Although Windows offers one alternate configuration it is quite circumstantial to access. The following PowerShell script will change network configurations with only a few clicks. It toggles them between dynamic and static, while it uses either static values you can enter or the ones the DHCP used itself before (default) (if you haven't executed any PowerShell scripts on your computer before, you will need to change your execution policy first - follow this tutorial to do so):

Get-WmiObject win32_networkadapterconfiguration | foreach-object { if($_.dhcpenabled -eq "true") {$akku = $_}}
if ($akku) {
$wmi = Get-WmiObject win32_networkadapterconfiguration | where{$_.ipenabled -eq "true" -and $_.dhcpenabled -eq "true"}
$ip = ($wmi.IPAddress[0])
$gate = $wmi.DefaultIPGateway
$subnet = ($wmi.ipsubnet[0])
else {
$wmi = Get-WmiObject win32_networkadapterconfiguration | where {($_.DefaultIPGateway) -and !($_.dhcpenabled)}
$akku = ""

This script will use the same values the DHCP used for your static configuration - you will want to set your own IP, Gateway and Subnet though. To do that just replace the bold printed values with the appropriate IPs in double-quotes (e.g. "").

To actually execute the script, you need to paste it into a notepad document and save it as .ps1 file. It has to be run with administrative rights, so either run it from an elevated powershell or create a link to the file's context menu that runs it in elevated mode.

If you experience issues with the character set, make sure that all double-quotes in the copied text look the same. If not, rewrite the appropriate ones.

Monitor Processes With Windows PowerShell

Maybe you have already come across applications that require you to rearrange things on your desktop for optimal visibility or which you only use in combination with other programs or items - an automated startup or rearrangement would come handy in those situation.

The following little PowerShell script allows just this - automatical actions on process start and/or end.

$target = "firefox"
$process = Get-Process | Where-Object {$_.ProcessName -eq $target}
while ($true)
while (!($process))
$process = Get-Process | Where-Object {$_.ProcessName -eq $target}
start-sleep -s 5
if ($process)
"Place action on process start here"
start-sleep -s 2
$process = Get-Process | Where-Object {$_.ProcessName -eq $target}
"Place action on process exit here"

The script above runs continuously until it is terminated or the current session is ended. With a wait time of 5 seconds to give the CPU a break it checks if the process is running - if not, it continues to check, if yes, it spills out some text you can replace with the action to perform on process start and waits until the process is ended. Afterwards, it returns some text to replace and continues to wait for process start again. Currently, the process that is monitored is firefox and is specified in the $target variable at the top of the code.

To run the script, copy and paste it into a notepad, save it as .ps1 file and schedule it on startup with the Windows Scheduled Tasks service if you like. To run the script completely without pop-ups, have a look here.

How to Execute PowerShell Scripts Without Pop-Up Window

PowerShell scripts are hard to run without any kind of popup. Without a small workaround, it may even be impossible, even if you specify the -WindowStyle Hidden switch - this will only result in the PowerShell window blinking up for a split second and disappearing afterwards.

You can circumvent this issue by launching the PowerShell script from a small VBScript which looks as follows:

command = "powershell.exe -nologo -command C:\Users\howtoforge\Desktop\loop.ps1"
set shell = CreateObject("WScript.Shell")
shell.Run command,0

Save the script as .vbs file. The -command switch is followed by the location of your PowerShell script - give the full path here (my PS script is on C:\Users\howtoforge\Desktop and is called loop.ps1). This VBS frame will cause the PowerShell script to work silently; it will no longer display any cmd window.

Windows Powershell Script to Export and Import Sound Schemes

Windows 7 offers the possibility to switch between preinstalled sound schemes and also create new ones and delete those again. What it does not provide however is a way to export and import those schemes to use them on other systems. There is a way to do this but it involves copying over all the custom sound files as well as exporting and importing specific registry keys. This might be a bit too complicated for someone who just wants all their Windows systems to play some nice bird chirp at logon.

Luckily, what is possible on Windows is also scriptable in PowerShell. Therefore the following script is able to export custom sound schemes into a zipped package, including all sound files and needed registry items and also import them onto another system. All the audio files used for the custom scheme to export need to be in the C:\Windows\Media directory - on import, they are all unpacked back there and will not be found if the registry points somewhere else.

$x = "nil"

function SelectFileDialog
param([string]$Title,[string]$Directory,[string]$Filter="Zip archives (*.zip) |*.zip")
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
$bFile = New-Object System.Windows.Forms.OpenFileDialog
$bFile.ShowHelp = $true
$bFile.Title = $Title
$bFile.InitialDirectory = $Directory
$bFile.Filter = $Filter
$Show = $bFile.ShowDialog()
If ($Show -eq "OK")
Return $bFile.FileName
Write-Error "Cancelled by user."

function NewZip
$l = $zipFilename.length-4
$iszip = $zipFilename.substring($l)
if ( $iszip -ne ".zip")
$zipFilename = $zipFilename + ".zip"
set-content $zipFilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
(dir $zipFilename).IsReadOnly = $false

function AddZip
$l = $zipFilename.length-4
$iszip = $zipFilename.substring($l)
if ( $iszip -ne ".zip")
$zipFilename = $zipFilename + ".zip"
}$l = $zipFilename.length-4
$iszip = $zipFilename.substring($l)
if ( $iszip -ne ".zip")
$zipFilename = $zipFilename + ".zip"
$shellApplication = new-object -com shell.Application
$zipPackage = $shellApplication.NameSpace($zipFilename)

foreach($file in $input)
Start-sleep -milliseconds 500

function ExtractZip
param([string]$zipFilename, [string] $destination)

$shellApplication = new-object -com shell.Application
$zipPackage = $shellApplication.NameSpace($zipFilename)
$destinationFolder = $shellApplication.NameSpace($destination)

$objshell = New-Object -ComObject Shell.Application
[void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Drawing”)
[void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)

$objform = New-Object System.Windows.Forms.Form
$objform.Text = “Export Windows 7 Sound Scheme”
$objform.Size = New-Object System.Drawing.Size(330,160)
$objform.StartPosition = “CenterScreen”

$objform.KeyPreview = $True
$objform.Add_KeyDown({if ($_.KeyCode -eq “Escape”) {$objform.Close()}})

$exportButton = New-Object System.Windows.Forms.Button
$exportButton.Location = New-Object System.Drawing.Size(20,70)
$exportButton.Size = New-Object System.Drawing.Size(75,23)
$exportButton.Text = “Export”

$importButton = New-Object System.Windows.Forms.Button
$importButton.Location = New-Object System.Drawing.Size(100,70)
$importButton.Size = New-Object System.Drawing.Size(75,23)
$importButton.Text = “Import”
$importButton.Add_Click({$x=”imp”; $objform.Close()})

$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Size(180,70)
$cancelButton.Size = New-Object System.Drawing.Size(75,23)
$cancelButton.Text = “Cancel”

$objlabel = New-Object System.Windows.Forms.Label
$objlabel.Location = New-Object System.Drawing.Size(10,20)
$objlabel.Size = New-Object System.Drawing.Size(280,40)
$objlabel.Text = “Do you want to export your current theme or import a new theme?”

[void] $objform.ShowDialog()

if($x -eq "nil") {exit}

if($x -eq "exp")
cd C:\Users\howtoforge\Desktop
$ts = (get-itemproperty (get-item HKCU:\AppEvents\Schemes).PSPath)."(default)"
$a = @()
$b = @()
newzip $ts
Get-ChildItem HKCU:\AppEvents\Schemes\Apps\ | Get-ChildItem | Get-ChildItem |
Foreach-Object {if ((get-itemproperty $_.PSPath)."(default)" -notlike "C:\Windows\Media\*\*"){($efg = ((get-itemproperty $_.PSPath).PSChildName));
if ($efg -eq $ts) { $a += ((get-itemproperty $_.PSPath)."(default)")
foreach ($i in $a){ if ($i) {$b += get-item $i}}
$b = $b | select -uniq
get-item $b | addzip $ts
reg export HKCU\AppEvents ($ts + ".reg")
get-item ($ts + ".reg") | addzip $ts
remove-item ($ts + ".reg")

if($x -eq "imp")
$p = SelectFileDialog
if ($p)
$ppp = (gci $p | select -expandproperty name)
$ps = $ppp.substring(0,$ppp.length-4)
extractzip $p C:\Windows\Media
regedit ("C:\Windows\Media\" + $ps + ".reg")
Start-sleep -milliseconds 10000
remove-item ("C:\Windows\Media\" + $ps + ".reg")

In order to be able to run the script, you need to enable running PowerShell scripts on your systems. Therefore, open a PowerShell as administrator and type in:

set-executionpolicy remotesigned

Now you can run selfmade or signed scripts. Copy and paste the script above into a notepad and find the line that was printed bold here - change my username in the path ("howtoforge") to yours. Then save it as .ps1 file.

Afterwards you can run the script by right-clicking it and running it in PowerShell or setting that as the default program to open ps1 scripts with. A prompt will pop up that will ask you if you want to ex- or import. Exporting will automatically export your current sound scheme to a zip file on your desktop (but only with the audio files lying in the said folder - exporting any schemes with files in a subfolder such as the Windows schemes will result in missing paths).

Copy the zipped package to the target system and run the script from there, choosing Import this time. Browse for the package and open it. The script will then put all the audio files to the C:\Windows\Media folder and import the registry file (a few pop ups will come up upon importing stuff into the registry, just accept them and everything should be fine).

If any issues should occur, make sure the zipped package is saved to a folder you have writing-permissions and everything for - if you changed it to something else than your desktop, this may easily happen.
If you are told that the registry file does not exist, this is because you waited too long to accept the import - after ten seconds, the .reg file is deleted to not clutter the Media folder. Just import again to solve it.

Windows Powershell Script to Sort Music From Folder to Library

The aim of the following script was to take music from a single folder with unsorted but tagged audio files and sort them into the music library according to artist and album. It often happens that you have audio files in your browser's download folder or your instant messenger's received files folder where they usually don't belong. The script should be able to move them into your music library and put them into correct folders named after the artist and the album they're on.


$controlssource = 1
$controlsdest = 1

$objshell = New-Object -ComObject Shell.Application
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$objform = New-Object System.Windows.Forms.Form
$objform.Text = "Move Audio Data"
$objform.Size = New-Object System.Drawing.Size(300,260)
$objform.StartPosition = "CenterScreen"

$objform.KeyPreview = $True
$objform.Add_KeyDown({if ($_.KeyCode -eq "Escape")

$movebutton = New-Object System.Windows.Forms.Button
$movebutton.Location = New-Object System.Drawing.Size(20,170)
$movebutton.Size = New-Object System.Drawing.Size(75,23)
$movebutton.Text = "Move"

$copybutton = New-Object System.Windows.Forms.Button
$copybutton.Location = New-Object System.Drawing.Size(100,170)
$copybutton.Size = New-Object System.Drawing.Size(75,23)
$copybutton.Text = "Copy"

$cancelbutton = New-Object System.Windows.Forms.Button
$cancelbutton.Location = New-Object System.Drawing.Size(180,170)
$cancelbutton.Size = New-Object System.Drawing.Size(75,23)
$cancelbutton.Text = "Cancel"

$objlabel = New-Object System.Windows.Forms.Label
$objlabel.Location = New-Object System.Drawing.Size(10,110)
$objlabel.Size = New-Object System.Drawing.Size(280,40)
$objlabel.Text = "Please specify whether you want to copy or to move your files. Moving the files will remove them from their original directory."

if ($controlssource -eq 1){
$objlabel2 = New-Object System.Windows.Forms.Label
$objlabel2.Location = New-Object System.Drawing.Size(10,10)
$objlabel2.Size = New-Object System.Drawing.Size(280,15)
$objlabel2.Text = "Path to file origin:"

if ($controlssource -eq 1){
$objtextbox = New-Object System.Windows.Forms.TextBox
$objtextbox.Location = New-Object System.Drawing.Size(10,25)
$objtextbox.Size = New-Object System.Drawing.Size(230,20)

if ($controlsdest -eq 1){
$objlabel3 = New-Object System.Windows.Forms.Label
$objlabel3.Location = New-Object System.Drawing.Size(10,50)
$objlabel3.Size = New-Object System.Drawing.Size(280,15)
$objlabel3.Text = "Path to music library:"

if ($controlsdest -eq 1){
$objtextbox2 = New-Object System.Windows.Forms.TextBox
$objtextbox2.Location = New-Object System.Drawing.Size(10,65)
$objtextbox2.Size = New-Object System.Drawing.Size(230,20)

if ($controlssource -eq 1){
$browsebutton1 = New-Object System.Windows.Forms.Button
$browsebutton1.Location = New-Object System.Drawing.Size(250,24)
$browsebutton1.Size = New-Object System.Drawing.Size(26,22)
$browsebutton1.Text = "..."
$browsebutton1.Add_Click({$fold1 = $objshell.BrowseForFolder(0, "Select Folder", 0, "");$objtextbox.Text = $fold1.self.path})

if ($controlsdest -eq 1){
$browsebutton2 = New-Object System.Windows.Forms.Button
$browsebutton2.Location = New-Object System.Drawing.Size(250,64)
$browsebutton2.Size = New-Object System.Drawing.Size(26,22)
$browsebutton2.Text = "..."
$browsebutton2.Add_Click({$fold2 = $objshell.BrowseForFolder(0, "Select Folder", 0, "");$objtextbox2.Text = $fold2.self.path})


#$objform.topmost = $True

[void] $objform.ShowDialog()

$sFolder = $objtextbox.Text
$mFolder = $objtextbox2.Text
#$sFolder = "C:\Users\Public\Music\Sample Music"
#$mFolder = "C:\Users\howtoforge\Music"
$objfolder = $objshell.namespace($sFolder)

if ($X -eq "nil") {exit}

foreach ($strfilename in $objfolder.items())
for ($a ; $a -le 266; $a++)
if ($objfolder.getDetailsOf($objfolder.items, $a) -eq "Contributing artists")
#if ($objfolder.getDetailsOf($objfolder.items, $a) -eq "Albuminterpret")
$artist = $objfolder.getDetailsOf($strfilename, $a)
if($objfolder.getDetailsOf($objfolder.items, $a) -eq "Album")
$album = $objfolder.getDetailsOf($strfilename, $a)
if ($artist -and $album)
if (!(test-path($mFolder + "\" + $artist + "\" + $album + $strfilename)))
new-item($mFolder + "\" + $artist + "\" + $album) -itemtype directory
if($x -eq "copy")
copy-item $strfilename.Path ($mFolder + "\" + $artist + "\" + $album)
if($x -eq "move")
move-item $strfilename.Path ($mFolder + "\" + $artist + "\" + $album)
clear-variable artist
clear-variable album

The script runs for every audio file in the specified folder that possesses both given details, here they are Contributing artists and Album (you can change it to look for different details but this does not always make sense since the script later creates the folders in the library depending on those data - there are different artist details however which can be chosen from, since not every audio file has all of them (album artist, contributing artists...). To change them, just change the single instance of them in the script. Adjust their names to the display language of your system!).

If the files have both details specified, the script goes to your library and, if not already present, creates a folder with the artist's title, a folder with the album title inside of that, and copies or moves the file to that location.

If you have fixed folders that you don't want to browse anew everytime you run the script, comment out the top two lines and the two bold lines, uncomment the two lines underneath the latter. Change the path given there to the path of your folders. You can also just uncomment one of them, just make sure to comment out the right lines when you uncomment one.

To run the script, copy and paste it into a notepad and save it as .ps1 file (select All Files from the type dropdown menu). Then right-click the file and run it with windows powershell. If it is not working, you might have to change your execution policy if you have not already done so. To accomplish that, search for powershell in the Windows menu search bar and right-click to run it as administrator. Enter

set-executionpolicy remotesigned

and run the script again. The script works finde on my Windows 7 Enterprise 64bit machine with PowerShell 1.0 installed, if some one has improvements to make I'd be glad to read.

Remove Desktop Clutter On Windows 7 With PowerShell

All of us know the habit of using the desktop as temporary working directory for all kinds of tasks, afterwards leaving most of the files there thinking you might still need them the next day. The day you use them again however never comes and so they remain on your desktop, eventually filling it up to the bottom right corner.
But for lazy people, there are lazy solutions to delay the task of cleaning and tidying up your computer! Just create a folder called Desktop on your Desktop and stuff everything you don't need into it! Here comes a PowerShell script that does this for you (replace the path to the desktop with the one to yours):

cd C:\Users\howtoforge\Desktop
$path = "C:\Users\howtoforge\Desktop"
$index = 0
$run = 1
while ($run -eq 1) {
if (test-path ($path + "\Desktop_" + $index)) {
else {
mkdir ($path + "\Desktop_" + $index)
$run = 0
gci $path |
? {$_.Name -notlike "Desktop_*" -and $_.Name -notlike "meta.ps1"} |
Foreach-Object { move-item $_ -destination ($path + "\Desktop_" + $index)}

This script creates a numbered "Desktop_x" folder, takes all the stuff from your desktop except system folders such as the recycle bin, shortcuts and the things you exclude in the script and throws them all inside the created folder.
The only thing you might want to adjust are the items the script excludes - these are given in the line

? {$_.Name -notlike "Desktop_*" -and $_.Name -notlike "meta.ps1"} |

Up to now, the script excludes all the items whose names begin with Desktop_, which is because the script is not supposed to crap its own folders, and the "meta.ps1" file, which is the name I saved the script under on my desktop.
Copy the script into a notepad and save it as .ps1 file - if you get an error message about converting to a different character set, cancel the saving. This happens upon copying the script from the website to notepad - to solve the issue, look through the script in your notepad for double-quotes and replace those that look odd with new ones. You should now be able to save the document without problems.
To add more files to exclude, copy and paste the bold part of the line (including the space character in front of it) right after itself and replace the name (which is meta.ps1) with the file you want to exclude (you may use wildcards (*) to select multiple files).
To run the script, right-click it and select Run with PowerShell.

Automatically Delete Older Folder Contents with Powershell on Windows 7

The aim of this guide is to create a folder whose content is deleted if the contained files have not been accessed longer than a specific time (this process is applied to single files, not the whole folder). I will choose two weeks for demonstration purposes (= 14 days). Such a folder can be used as temporary folder of any kind, be it for downloaded files/installers or to just keep the desktop clutter-free.
This can be achieved with a combination of PowerShell script and Windows task scheduler. The folder that I will use for this will be C:\Users\howtoforge\Desktop\Temp and is located on my desktop for easy access. To keep order to it, create another folder for your custom scripts if you haven't already got one, mine will be C:\Scripts.
Open a new instance of notepad and save it in your scripts folder as delete_temp.ps1. .ps1 is the file extension for PowerShell scripts. Now enter following into the script:

cd "C:\Users\howtoforge\Desktop\Temp";
Get-Childitem | Foreach-Object {if ($_.LastAccessTime -le (get-date).adddays(-14)) {remove-item -recurse -force $_}};

Save the script again. What it does: the script changes into the directory that we want to observe, looks at its items and then deletes every one whose last access time is older than 14 days recursively (it only looks at the items directly placed in the folder, not at subdirectories). The time interval is specified in the adddays attribute of the get-date function here (which can also be addmonths, addhours, etc...) and is a negative number to actually subtract the number of days from the present date. You can change it to your likings.
The script being ready, you have to configure PowerShell to enable calling scripts - therefore open an elevated command line (search the menu for cmd, right-click and select Run as administrator). Open PowerShell by entering


Afterwards, enter

Set-ExecutionPolicy RemoteSigned

to enable calling scripts. Now you can test your script by right-clicking it and selecting Run with PowerShell. If nothing goes wrong (no red text in the flashing window), proceed to schedule the task, otherwise check your script for errors.

To schedule the task, open Control Panel > System and Security > Administrative Tools > Schedule Tasks. On the left pane, select Task Scheduler Library, then right-click the central task-list and select Create New Task.
On the General tab, give the task a name and a description. Furthermore, choose your version of Windows and optionally choose to run it with highest privileges.
The Trigger tab defines what will call the script - hit New and choose one or more of the various possibilities and events. I choose to run the script when the machine goes idle, since the script will blink up in a PowerShell window when called, and I don't want that to disturb my work (although it's really only a split second if you don't delete several GB of files).
On the Actions tab you define what to do - hit New again. Now don't enter the actual script as program to run - this goes to the Add arguments line (enter the full path here). What you need to do is to call the PowerShell executable with the script as an argument. I use PowerShell 1.0 which is located in C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe - enter this path into the Program/script line and hit OK.
Now configure the next two tabs for your needs and hit OK again to create the task.

The selected folder will then be scanned for files that haven't been accessed for longer than the given period every time the task triggers.

Wrap VBScripts into .exe Format

To convert your VBScript to an .exe file, or rather make them look like one, there is a native Windows tool called IExpress which you can access through your menu's searchbar.

Select Create new Self Extraction Directive file and choose Extract files and run an installation command afterwards. Enter a package title and decide whether you want the user to be prompted or not and if you want a licence to be shown. Now browse the executables you want to wrap and select the files for installation in the next window. If they are not displayed in the dropdown menu then type their name in again manually.
If you want multiple scripts to be installed, enter cmd /c script1.vbs && script2.vbs for example. After some more configuration the executable will be placed in the directory you specified in one of the last steps.

Send Mails Via Remote Server With VBScript (Windows)

You can use MS Windows' VBScript to write a script that is able to log into a remote mail server such as googlemail or any other with your account data and send mails from that server. This can be used to retrieve logs via attachments or to just automate mail processes. The bare script to send a mail looks as follows (the apostrophe after a line signals a comment to the lines content, it does not belong to the script. The data all go inside the doublequotes if there are any):

Set objMessage = CreateObject("CDO.Message")

objMessage.Subject = "Type in the mail's subject here"

objMessage.From = " <the sender mail goes here, you need the login data for it>"
'The mail address goes inside the tags

objMessage.To = "the receiver mail goes here"

objMessage.TextBody = "Here goes the actual mail message"

objMessage.Addattachment "Fill in the complete path to your attachment, otherwise leave complete line"

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
determines whether you use local smtp (1) or network (2)

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "
Fill in your smtp (outgoing) server"
You can find your provider's server address somewhere on the homepage or by googling for smtp server lists

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
Determines the authentication mode. 0 for none, 1 for basic (clear text), 2 for NTLM

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "
should be the same as the sender mail - login data for your server"

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "
your email's password - login data for your server"

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
This is the default port used by most servers. Find out if yours is using a different one if there are problems

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
Use SSL? True or False

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

'Maximum time connection is tried to be established



It is recommended not to use this script on a computer you are not the only user of, since your email and its password are openly visible. However you can just create a new one for that purpose. You can easily embed this script into any other VBScript, schedule it or do whatever you want with it.

Use Double-Quotes in Quoted Expressions with ASCII Codes in Windows Powershell

While scripting, you may encouter the problem that you have an expression that uses double-quotes as tags and therefore cannot use any double-quotes inside these tags. You can circumvent this problem by using ASCII codes to add certain keys. This is done by tagging out, joining with ASCII code and joining with the tagged expression again. Look at the following Visual Basic Script code:

set objshell = wcript.createobject("wscript.shell")
objshell.run "C:\Windows\system32\cmd.exe /K cd " & Chr(34) &
"C:\Users\howtoforge\Desktop\A Folder" & Chr(34) & ""

The double-quotes inside the run command are represented by the expression Chr(34) that adds the ASCII character with the ID 34, which is double-quotes. This expression is outside the regular quotes and is joint with the command with an Ampersand (&). Thus the above line would result in following line being entered into cmd:

cd "C:\Users\howtoforge\Desktop\A Folder"