Re: Can't register Windows Scripting Host with Windows 7
- From: "MikeD" <nobody@xxxxxxxxxxx>
- Date: Sat, 5 Dec 2009 18:27:59 -0500
"will_456" <will_456@xxxxxxxxxx> wrote in message news:hRySm.60404$ze1.22912@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thanks for the advice. My app has been in use since 1999 and is designed to work on Win 95 onwards hence the installer has always include WSH.
One functions I have used it for in the program is to find the location of the users special folders eg. documents folder and then to delete a subfolder.
I had used other methods but they were quite complex. WSH allowed me to do it with just a few lines.
Not really good reasons because all of those can be done fairly easily without it. If for no other reason, you should consider getting rid of the WSH and using either API or VB's own statements, functions, etc. to eliminate the dependency. Also, some users and many sysadmins will have removed that file to prevent scripts from using it for malicious purposes. So from that standpoint alone, it's really not a good idea to use it in your app.
All the "special folders" can be obtained by using the SHGetSpecialFolderPath Win32API function. You can write a wrapper function around this API function so you only need to make one call in your app whenever you need a special folder. Here's some code:
-----BEGIN CODE
Private Const MAX_PATH As Long = 260
Private Declare Function SHGetSpecialFolderPath Lib "Shell32" Alias "SHGetSpecialFolderPathA" (ByVal hwndOwner As Long, ByVal lpszPath As String, ByVal nFolder As Long, ByVal fCreate As Long) As Long
Public Enum SHSpecialFolderIDs
CSIDL_DESKTOP = &H0& ' <desktop>
CSIDL_INTERNET = &H1& ' Internet Explorer (icon on desktop)
CSIDL_PROGRAMS = &H2& ' Start Menu\Programs
CSIDL_CONTROLS = &H3& ' My Computer\Control Panel
CSIDL_PRINTERS = &H4& ' My Computer\Printers
CSIDL_PERSONAL = &H5& ' My Documents
CSIDL_FAVORITES = &H6& ' <user name>\Favorites
CSIDL_STARTUP = &H7& ' Start Menu\Programs\Startup
CSIDL_RECENT = &H8& ' <user name>\Recent
CSIDL_SENDTO = &H9& ' <user name>\SendTo
CSIDL_BITBUCKET = &HA& ' <desktop>\Recycle Bin
CSIDL_STARTMENU = &HB& ' <user name>\Start Menu
CSIDL_MYDOCUMENTS = &HC& ' logical "My Documents" desktop icon
CSIDL_MYMUSIC = &HD& ' "My Music" folder
CSIDL_MYVIDEO = &HE& ' "My Videos" folder
CSIDL_DESKTOPDIRECTORY = &H10& ' <user name>\Desktop
CSIDL_DRIVES = &H11& ' My Computer
CSIDL_NETWORK = &H12& ' Network Neighborhood (My Network Places)
CSIDL_NETHOOD = &H13& ' <user name>\nethood
CSIDL_FONTS = &H14& ' windows\fonts
CSIDL_TEMPLATES = &H15&
CSIDL_COMMON_STARTMENU = &H16& ' All Users\Start Menu
CSIDL_COMMON_PROGRAMS = &H17& ' All Users\Start Menu\Programs
CSIDL_COMMON_STARTUP = &H18& ' All Users\Startup
CSIDL_COMMON_DESKTOPDIRECTORY = &H19& ' All Users\Desktop
CSIDL_APPDATA = &H1A& ' <user name>\Application Data
CSIDL_PRINTHOOD = &H1B& ' <user name>\PrintHood
CSIDL_LOCAL_APPDATA = &H1C& ' <user name>\Local Settings\Applicaiton Data (non roaming)
CSIDL_ALTSTARTUP = &H1D& ' non localized startup
CSIDL_COMMON_ALTSTARTUP = &H1E& ' non localized common startup
CSIDL_COMMON_FAVORITES = &H1F&
CSIDL_INTERNET_CACHE = &H20&
CSIDL_COOKIES = &H21&
CSIDL_HISTORY = &H22&
CSIDL_COMMON_APPDATA = &H23& ' All Users\Application Data
CSIDL_WINDOWS = &H24& ' GetWindowsDirectory()
CSIDL_SYSTEM = &H25& ' GetSystemDirectory()
CSIDL_PROGRAM_FILES = &H26& ' C:\Program Files
CSIDL_MYPICTURES = &H27& ' C:\Program Files\My Pictures
CSIDL_PROFILE = &H28& ' USERPROFILE
CSIDL_SYSTEMX86 = &H29& ' x86 system directory on RISC
CSIDL_PROGRAM_FILESX86 = &H2A& ' x86 C:\Program Files on RISC
CSIDL_PROGRAM_FILES_COMMON = &H2B& ' C:\Program Files\Common
CSIDL_PROGRAM_FILES_COMMONX86 = &H2C& ' x86 Program Files\Common on RISC
CSIDL_COMMON_TEMPLATES = &H2D& ' All Users\Templates
CSIDL_COMMON_DOCUMENTS = &H2E& ' All Users\Documents
CSIDL_COMMON_ADMINTOOLS = &H2F& ' All Users\Start Menu\Programs\Administrative Tools
CSIDL_ADMINTOOLS = &H30& ' <user name>\Start Menu\Programs\Administrative Tools
CSIDL_CONNECTIONS = &H31& ' Network and Dial-up Connections
CSIDL_COMMON_MUSIC = &H35& ' All Users\My Music
CSIDL_COMMON_PICTURES = &H36& ' All Users\My Pictures
CSIDL_COMMON_VIDEO = &H37& ' All Users\My Video
CSIDL_RESOURCES = &H38& ' Resource Direcotry
CSIDL_RESOURCES_LOCALIZED = &H39& ' Localized Resource Direcotry
CSIDL_COMMON_OEM_LINKS = &H3A& ' Links to All Users OEM specific apps
CSIDL_CDBURN_AREA = &H3B& ' USERPROFILE\Local Settings\Application Data\Microsoft\CD Burning
' unused = &H003c&
CSIDL_COMPUTERSNEARME = &H3D& ' Computers Near Me (computered from Workgroup membership)
End Enum
Public Function GetSpecialFolder(ByVal FolderID As SHSpecialFolderIDs) As String
'SHGetSpecialFolderPath is not necessarily supported under Win95. It can be called
'under Win95 if IE4 AND the Desktop Update are installed.
Dim sBuffer As String
sBuffer = String$(MAX_PATH, vbNullChar)
'For Win98 and higher
Call SHGetSpecialFolderPath(0&, sBuffer, FolderID, 0&)
GetSpecialFolder = StripNulls(sBuffer)
End Function
Public Function StripNulls(ByVal sText As String) As String
'Returns all characters up to a null character.
'If the string does not contain a null character,
'the string is returned unmodified.
Dim lNullPos As Long
lNullPos = InStr(sText, vbNullChar)
If lNullPos Then
StripNulls = Left$(sText, lNullPos - 1)
Else
StripNulls = sText
End If
End Function
-----END CODE
To delete the subfolder, just use VB's own RmDir statement or any of a number of API functions.
--
Mike
.
- References:
- Can't register Windows Scripting Host with Windows 7
- From: will_456
- Re: Can't register Windows Scripting Host with Windows 7
- From: mayayana
- Re: Can't register Windows Scripting Host with Windows 7
- From: will_456
- Can't register Windows Scripting Host with Windows 7
- Prev by Date: Re: Need WritePrivateProfileString replacement
- Next by Date: Re: Need WritePrivateProfileString replacement
- Previous by thread: Re: Can't register Windows Scripting Host with Windows 7
- Next by thread: Re: Can't register Windows Scripting Host with Windows 7
- Index(es):
Relevant Pages
|