Never having used the Scripting Host, take this for what it’s worth….
Have you set a reference to the Windows Scripting Host Shell Object?
Maybe that is the difference?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » VBS/VBA/VB and registry editing… (VB6)
Help a dumb and confused newbie.
If I use VBScript or even VBA, I can edit the registry by Creating the Windows Scripting Host Shell Object and then using simple commands like RegWrite or RegDelete:
Set WshShell = WScript.CreateObject(“WScript.Shell”)
WshShell.RegWrite …
However, as best I can tell, this is not an option for VB6. To edit the registry using VB6, I need to:
1) Declare each editing function from advapi32.dll separately (e.g., Declare Function RegSetValueEx…)
2) Declare each parameter I might use with a given function (e.g., hkey, ipValueName)
3) Declare a Type for each parameter (e.g., As Long).
4) Define Constants for the hives and data values (e.g., Const REG_SZ = 1)
5) Define Constants for registry permisions (e.g., Const KEY_WRITE = &H20006)
Then, I can use VB6 to edit the registry. Is this a correct assumption??
Is there no way to invoke the Windows Scripting Host Shell Object in VB6 like I can in VBS and VBA?
Also, can I stick ALL the Declarations and Constants I need to edit the registry in single “.bas” module, and then ‘refer to’ or ‘call on’ this module each time I want to have a VB6 program edit the registry?
Please respond as you would to an eight year old. Some people have said I frequently act that old anyway! ;-] THANK YOU.
That does not make sense to me!
You are saying that programmers go through the hassles of using the API to edit the registry… “to keep malicious scripts from executing from emails and web downloads.”
I am not sure I follow that logic.
———————————————–
If you are instead saying the users disable the WSH for this reason, then MAYBE that makes sense — until you think about it for about two seconds. Most people disable the WSH by simply disabling the file extension associations to the WSH executable.
This does NOT render the WSH inoperable, but it does prevent .vbs, js, .wsf, and other files from easily running. Even with every single WSH file extension DIS-associated, the engine still runs this code quite easily.
Hmmm… you should know this…
I can even go so far as to rename (and therefore disable) the WSH executable entirely. And guess what??
I can STILL run the VBA code and edit the registry.
So… I do not think “disabling WSH” in any of the usual fashions will stop this. I suspect only completely removing WSH from your system would be sucessful — but I suspect Windows and especially IE would not like that…
Renaming it isn’t how the administrators block it, and if it *is* blocked, then you won’t be able to do it that way.
You can always use GetSetting and SaveSetting to create and populate or read and individual keys if you don’t want to bother with GetPrivateProfileString and WritePrivateProfileString.
Interesting. How do administators block it? Please tell me as I would love to test this.
I do not think GetSettings and SaveSettings are going to do me any good. As best I can tell, they ONLY function in HKLMSoftware key — and that is pretty limited.
Additionally, GetPrivateProfileString and WritePrivateProfileString appear to be for .INI files — not the registry. How are those going to help me editing the registry???
I’m not doing it because I don’t do network administration anymore and haven’t in years, but I’ve worked in offices in the recent past where it definitely *was* disabled. The whole scripting host is disabled and it has nothing to do with what programmers want to do, it is a security issue to protect networks from attack. Trying to get around any network security issue is a good way to get fired in that kind of environment … especially if you happen to succeed.
It looks to me that the usual mechanisms of preventing email attachment scripts from running are not going to be effective at stopping this technique.
The ‘Set WshShell = CreateObject(“WScript.Shell”)’ method utilizes only two files that are a sub-set of the WSH. I best I can tell, most people do not disable these. I even wonder if IE uses these to help run script.
The two files are:
wshom.ocx – Windows Script Host Runtime Library (an ActiveX control)
scrrun.dll – Microsoft ® Script Runtime
So, unless ‘disabling WSH’ disables these exact files, then it looks to me like the WshShell method should work.
Removing or renaming the WScript.Shell object-identifier (ProgID? whatever it’s called) in the Registry would seem to kill it. Don’t know if anyone does it that way. I wonder if you could do it from a VBScript that instantiates that object and then, in a sense, commits suicide…
As for GetPrivateProfileString, there’s documentation in the Word VBA help files on how to use it to read Registry stuff. Not sure if the WinAPI works the same way as Word’s specialized versions.
Yes, someone *could* disassociate the WScript.Shell from its Class Identifier ({72C24DD5-D70A-438B-8A42-98424B88AFB8}), or remove the InProcServer32 entry for the Class ID — which is the WSHOM.OCX file I listed above.
However, that would generally not be considered as part of the standard method of “disabling WSH”. From my view, most administrators simply want to prevent their users from inadvertantly running scripts. To do that, they either dissociate the WSH file extensions (.vbs, .js. .wsf, etc.) from wscript.exe — or rename wscript.exe.
Interestingly, since WinME and Win2K-XP have WSH as part of the operating system, that seems to be the recommended method. One could un-install WSH in Win9x from Add/Remove Programs; whether that removes the WScript.Shell object and wshom.ocx is not clear to me…
Other references on this are:
http://apcsnh.com/vacm/wshremove.html%5B/url%5D
http://www.sophos.com/support/faqs/wsh.html%5B/url%5D
http://securityresponse.symantec.com/avcen…pt.hosting.html%5B/url%5D
BTW, IE does not seem to utilize the WSH files to run script — or at least I did not catch it doing this. It seemed to only utilize the iexplore.exe file — so all the script interpreting function might be built inside that program itself.
________________________________________________
Jeff, the only logical answer I can come up with is that using the API functions is the more powerful method. If you need to do more detailed or extensive registry editing or *enumerating* of mulitple values, then you must use the API functions. If you simply want to read and write to a value or two, the WScript.Shell function seems to suffice.
Make sense?
> BTW, IE does not seem to utilize the WSH files to run script — or at least I did not catch it doing this. It seemed to only
> utilize the iexplore.exe file — so all the script interpreting function might be built inside that program itself.
Unless the script needs one of the objects accessible through WSH, I think you’re right that IE is pretty much self-sufficient (not counting the script engine DLLs).
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications