Featured Resource:

line

Newsletter

Email Address:


line

Ask the Expert

Have a question for our resident expert? Email your questions to Bob or post in the Forum.

September 26, 2007

Run Commands Elevated In Batch Scripts

While there is no elevation command in Vista so that your tools will run with administrative privileges, there is the Elevate Command PowerToy which can get the job done. It was written by Michael Murgolo, a consultant with Microsoft Consulting Services

The tool is discussed here:
http://www.microsoft.com/technet/technetmag/issues/2007/06/UtilitySpotlight/default.aspx.

And is available for download here:

http://www.technetmagazine.com/code07.aspx

Scroll down to : June 2007 and it is listed under “Utility Spotlight: Script Elevation PowerToys for Windows Vista” (Utility2007_06.exe)

Just give it a simple -? to view the syntax, but as you might expect it is simply:

Elevate cmd.exe

Any tool, or arguments for this such as opening a specific file or running a specific script follow just as you would normally enter them at the command line.

September 11, 2007

Vista's Symbolic Link Feature

Similar to junctions, symbolic links take the feature a couple of steps further. While junctions are limited to the NTFS 5.0 system, symbolic links do not share this restriction. Even better, you can link to individual files as opposed to only folders as is the requirement of junctions.

The feature is designed to aid in migration and application compatibility (particularly with UNIX operating systems). They are transparent to users and appear as normal files or directories. As such, you can fake programs and the operating system into using alternate names and references to files and folders with this feature.

By default only members of the administrators group can create links, but you can adjust this via local security policy if you wish:

Secpol.msc > Security Settings > Local Policies > User Rights Assignment > Create symbolic links

Note: if you make a change here, you’ll need to log out and back in again for the change to take effect. However, you may just want to run your command prompt as administrator to get the job done as to write a file to a system location you will need such permission anyway.
To create a symbolic link, use the mklink command. For example the below command line will create a symbolic link to the windows directory named “win” (note that by default links are created to files so you must specify the /d argument for a directory link)…

mklink /d win c:\windows

 
Continue reading Vista's Symbolic Link Feature...

September 10, 2007

SCWCMD.EXE

Windows Server 2008's Security Configuration Wizard (SCW) includes a corresponding command line, SCWCMD.EXE, which lets you automate the application of security policies generated through the wizard's graphical interface. SCW produces output in XML format which is incompatible by default with GPOs. The following command line may be used to convert SCW output into a readable format for inclusion in a GPO…

scwcmd transform /p:MyPolicyFile.xml /g:MyGPOName

This transforms the XML file into a new GPO and must naturally be run with domain administrator privileges. The resulting GPO (saved to saved under the %SYSTEMROOT%\SECURITY\MSSCW\POLICIES) will include the contents of the SCW XML file into a handful of sections within the GPO. These settings will include: Security Settings, IP Security Policies and Windows Firewall. This new GPO must then be linked to appropriate OUs to be applied.

You can use SCW to create new policies, edit existing policies, apply policies and even roll back the assignation of a security policy.

More information on the Security Configuration Wizard can be found .

August 14, 2007

Group Policy Inventory

GPInventory.exe collects Group Policy (and other information) computers in your network by running multiple Resultant Set of User Policy (RSOP) and Windows Management Instrumentation (WMI) queries. You can export results to either an XML or a text file (most easilly analyzed in Excel or other spreadsheet application).

RSOP Queries
* Perform a software inventory for users and computers
* Report on what applications are installed on computers
* Monitor the rollout of new GPOs
* Identify computers that have not downloaded and applied new GPOs

WMI Queries
* Report hardware inventory
* Scan computers for the presence of a specified hotfix
* Get disk space information
* Test a WMI filter before implementing it in the domain

Supported Operating Systems: Windows 2000; Windows Server 2003; Windows XP (also requires you have .NET Framework version 1.0 or later)

July 17, 2007

System Configuration: Tools

The "Tools" tab of the system configuration applet offers shortcuts to a number of helpful tools and shows you the path and filename for each:

About Windows
C:\Windows\system32\winver.exe

System Information
C:\Windows\System32\msinfo32.exe

Remote Assistance
C:\Windows\System32\msra.exe

System Restore
C:\Windows\System32\rstrui.exe

Computer Management
C:\Windows\System32\compmgmt.msc

Event Viewer
C:\Windows\System32\eventvwr.exe

Programs
C:\Windows\System32\appwiz.cpl

Security Center
C:\Windows\System32\wscui.cpl

System Properties
C:\Windows\System32\control.exe system

Internet Options
C:\Windows\System32\inetcpl.cpl

Internet Protocol Configuration
C:\Windows\System32\perfmon.exe

Performance Monitor
C:\Windows\System32\cmd.exe /k %windir%\system32\ipconfig.exe

Task Manager
C:\Windows\System32\taskmgr.exe

Disable UAC
C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f

Enable UAC
C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 1 /f

Command Prompt
C:\Windows\System32\cmd.exe

Registry Editor
C:\Windows\System32\regedt32.exe

July 15, 2007

VSSAdmin - Working with Volume Shadow Service

VSSAdmin.exe is the Volume Shadow Copy Service administrative command-line tool. VSSAdmin command may be run by anyone, but most of its functions require admin access to I recommend starting with a command prompt that has been run as Administrator.

A third party application could be running as a provider of VSS, but most systems will simply have MS Software Shadow Copy provider". To see a list of providers, type:

vssadmin list providers

sample result

Provider name: 'MS Software Shadow Copy provider 1.0'
Provider type: System
Provider Id: {b5946137-7b9f-4925-af80-51abd60b20d5}
Version: 1.0.0.7

So what kind of space are you loosing to this feature? Details may be displayed with the following command:

vssadmin list shadowstoreage

sample result:

 
Continue reading VSSAdmin - Working with Volume Shadow Service...

June 19, 2007

Command Prompt Tricks - Part 1

One very handy thing I mentioned before is that you can hit tab to auto-complete file names and directory names from the command prompt. If you are in the command prompt, you've likely got your hands on the keyboard so tricks like these are very handy to speed things along…


Moving around...

Ctrl-Left Arrow = move back one word
Ctrl-Right Arrow = move forward one word
Home = move to beginning of line
End = move to the end of line


Recalling commands you entered...

Up Arrow = display previous command entered
Page Up = display oldest command entered
Down Arrow = display next command entered
Page Down = display newest command entered


Repeating Typed Text...

F1 = repeat first character typed in preceding line (hit again for next)
F2 + = repeat first character typed in preceding line up to (where key is the first character in the preceding line to which you wish to repeat)
F3 = repeat text typed in preceding line
Esc = erase current line
F7 = show all entries in command buffer
Alt-F7 = clear all entries in command buffer

June 3, 2007

Command Prompt Here?

When you are working with scripts and command line tools, it not uncommon that you want a command prompt in the folder where these scripts and command line tools are stored. The easy thing to do would be to create a shortcut to the command prompt that opens at that location:

1) right click on the desktop (or in the folder where you want your shortcut and select "New" > "Shortcut".
2) for location of the item, simply enter "cmd.exe" (you don't need to specify the path because it is located in the system path) and press the "Next" button
3) next, give the shortcut a friendly name, like "My Scripts" and press the enter key
4) now right click on your new shortcut and choose "Properties"
5) the default tab shown should be the "Shortcut" tab. On this tab enter the desired folder path in the field marked "Start in" and you are done.

But suppose you don't keep all your scripts or command line tools in one place. In that case a more dynamic way of getting there is in order and here's the trick: add "Command Prompt Here" to your file explorer context menu. Here's how:

Launch a command prompt with elevated privileges and enter the following command:

reg add "HKLM\software\classes\folder\shell\Command Prompt Here\Command" /ve /d "cmd.exe /k pushd %L" /t REG_SZ

That does it...

cmd-here.jpg

May 16, 2007

Drvload for Windows PE

I wrote before about the Peimg tool and its ability to let you inject drivers into an offline Windows PE image. There is another tool provided for installing drivers to a booted Widnows PE image. This tool is Drvload and it can be helpful in loading drivers that might give you trouble when trying Peimg.

If you are automating things in your image startnet.cmd is a logical place for this command-- before or after the wpeinit call would depend upon if you were loading a nic driver or not.

The only parameter you need pass it is the path to an .inf file (which should obviously be in a folder with any required source files it depends upon). If the driver. sys file requires a reboot, you won't be able to use Drvload, but if it is the inf you supply that is requesting a reboot, Drvload will ignore it.

One cool thing about it is that you can load multiple drivers in a single command line, but specifying multiple .inf files (separated by comma's). Wildcards are not supported.

As you would expect, if any drivers failed to install non-zero %errorlevel% value (zero for success).

Note: This tool replaces the earlier drvinst command line tool from earlier releases of Windows PE.

 
Continue reading Drvload for Windows PE...

May 1, 2007

Controlling UAC from the Command Line

Turn it off:

C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f

Turn it back on:

C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 1 /f

As I’m sure you can see, this simply updates the EnableLUA registry key (one is on, zero is off) which is located in the HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System subkey of the registry. Naturally you’ll need admin privileges to change a HKLM settings so if you want to run this, you’ll need to do it from a command prompt being run as administrator.

Now the bad news: there is no way around it, this setting requires a restart of the computer. If you are trying to script that too, check out the shutdown command ;)

Library Resources

line
line

Bob Kelly's Bio:

Bob Kelly is the founder of AppDeploy.com — a resource focused on desktop management products and practices. He is author of the Start to Finish Guide to Scripting with KiXtart and The Definitive Guide to Windows Desktop Administration. He is also president and co-founder of iTripoli, Inc. who provide AdminScriptEditor.com, home to an integrated suite of scripting tools and a shared library of scripts and language help. Not enough? For more on Bob click here.