Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows 7 System Variables

Status
Not open for further replies.

danno74

IS-IT--Management
Nov 13, 2002
295
0
0
US
Greetings all,

Still working on my scripts for Windows 7, found the following site that lists system variables for W7:


I want to remove icons created by programs I install, so I was looking for the default all user desktop directory variable, which according to this site is this:

%CSIDL_COMMON_DESKTOPDIRECTORY%

Here is the syntax I'm using:

DEL /F "%CSIDL_COMMON_DESKTOPDIRECTORY%\program.lnk"

I try to use it and it's not working. Any ideas? Thanks.

- Dan
 
These aren't "Windows 7 system variables" at all. They're defined by the User State Migration Tool for internal use in its XML files.


It might be easier just use a small script to look up the specific folder you need and delete your file or files.


If you want these sorts of environment variables you'll have to set them yourself. A script can be useful for looking up current values and setting the variables. Even a script that can set such variables doesn't help directly because new environment variables won't be added to cmd.exe's Environment Block until the next time you run it.

However such a script can still be useful, though it needs to be rerun if the special folders involved are ever relocated.

SetEnv.vbs
Code:
Option Explicit
'Set a Special Folder environment variable.  This will add
'an environment variable to the User profile but it will
'not be visible to the current command shell (cmd.exe)
'instance.

'Most of the more useful values:
Private Const CSIDL_DESKTOP = &H0000
Private Const CSIDL_PROGRAMS = &H0002
Private Const CSIDL_PERSONAL = &H0005
Private Const CSIDL_FAVORITES = &H0006
Private Const CSIDL_STARTUP = &H0007
Private Const CSIDL_STARTMENU = &H000B
Private Const CSIDL_MYDOCUMENTS = &H000C
Private Const CSIDL_MYMUSIC = &H000D
Private Const CSIDL_MYVIDEO = &H000E
Private Const CSIDL_DESKTOPDIRECTORY = &H0010
Private Const CSIDL_DRIVES = &H0011
Private Const CSIDL_FONTS = &H0014
Private Const CSIDL_TEMPLATES = &H0015
Private Const CSIDL_COMMON_STARTMENU = &H016
Private Const CSIDL_COMMON_PROGRAMS = &H0017
Private Const CSIDL_COMMON_STARTUP = &H0018
Private Const CSIDL_COMMON_DESKTOPDIRECTORY = &H0019
Private Const CSIDL_APPDATA = &H001A
Private Const CSIDL_LOCAL_APPDATA = &H001C
Private Const CSIDL_COMMON_FAVORITES = &H001F
Private Const CSIDL_COMMON_APPDATA = &H0023
Private Const CSIDL_WINDOWS = &H0024
Private Const CSIDL_SYSTEM = &H0025
Private Const CSIDL_PROGRAM_FILES = &H0026
Private Const CSIDL_MYPICTURES = &H0027
Private Const CSIDL_PROFILE = &H0028
Private Const CSIDL_SYSTEMX86 = &H0029
Private Const CSIDL_PROGRAM_FILESX86 = &H002A
Private Const CSIDL_PROGRAM_FILES_COMMON = &H002B
Private Const CSIDL_PROGRAM_FILES_COMMONX86 = &H002C
Private Const CSIDL_COMMON_TEMPLATES = &H002D
Private Const CSIDL_COMMON_DOCUMENTS = &H002E
Private Const CSIDL_COMMON_MUSIC = &H0035
Private Const CSIDL_COMMON_PICTURES = &H0036
Private Const CSIDL_COMMON_VIDEO = &H0037
Private Const CSIDL_CDBURN_AREA = &H003B

Private strArg, lngCSIDL, strFolder

Private Sub Usage(ByVal PoundSign)
    WScript.Echo PoundSign & "Usage:" & vbNewLine _
               & vbNewLine _
               & "cscript //nologo " & WScript.ScriptName _
               & " <CSIDL value name>" & vbNewLine _
               & vbNewLine _
               & "Add/set an environment variable for the supplied CSIDL Special" _
               & vbNewLine _
               & "Folder value (by name) to the current User's profile." _
               & vbNewLine _
               & vbNewLine _
               & "Example: csidl //nologo " & WScript.ScriptName _
               & " CSIDL_DESKTOP" & vbNewLine _
               & vbNewLine _
               & "         Adds/sets the User environment variable CSIDL_DESKTOP" _
               & vbNewLine _
               & "         to the folder indicated by CSIDL_DESKTOP."
End Sub

If WScript.Arguments.Count <> 1 Then
    Usage "#Wrong number of parameters." & vbNewLine & vbNewLine
    WScript.Quit 1
Else
    strArg = WScript.Arguments(0)
    If InStr(strArg, "?") > 0 Or UCase(strArg) = "HELP" Then
        Usage "#"
    Else
        lngCSIDL = Eval(strArg)
        If VarType(lngCSIDL) = vbEmpty Then
            WScript.Echo "#Unknown CSIDL value: " & WScript.Arguments(0)
            WScript.Quit 2
        Else
            With CreateObject("Shell.Application")
                strFolder = .NameSpace(lngCSIDL).Self.Path
            End With
            With CreateObject("WScript.Shell").Environment("User")
                .Item(strArg) = strFolder
            End With
        End If
    End If
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top