I want to change the Source file Server path location in the reg path
HKEY_CLASSES_ROOT\Installer\Products\Product GUID\SourceList\Net\1 of every client machines,
as we have removed the existing Application server with a new one...We were able to change the old server path to new server path using the "replace" function in vbscript.
Set objWS = CreateObject("WScript.Shell")
strKeyValue = objWS.RegRead("HKEY_CLASSES_ROOT\Installer\Products\A7C4EB2D0BDDF2A43BDD35A498E12655\SourceList\Net\1")
newstrKeyValue = Replace(strKeyValue,"\\INADCSRV11" ,"\\INADCSRV12")
newstrKeyValue2 = Replace (newstrKeyValue ,"SMSPKGC$" ,"SMSPKGP$")
Const HKEY_CLASSES_ROOT = &H80000000
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "Installer\Products\A7C4EB2D0BDDF2A43BDD35A498E12655\SourceList\Net\"
strValueName = "1"
strValue = newstrKeyValue2
oReg.SetExpandedStringValue HKEY_CLASSES_ROOT,strKeyPath,strValueName,strValue
but we are stuck in reading the reg values....
Product GUID is a variable.First we have to read till that path and then after reading one GUID, again we have to read the complete path
HKEY_CLASSES_ROOT\Installer\Products\Product GUID\SourceList\Net\1 and then change the server name
Please let me know anyone have encountered any situation like this.
Assuming I'm not mistaken and you want to enumerate all the subkeys within a certain key this this answer from another question shows code that does this.
Related
I have to read registry value "GDIProcessHandleQuota" so that I have write below code
strKeyPath = "Schema\wcm://Microsoft-Windows-Win32k-Settings?version=6.1.7600.16385&language=neutral&processorArchitecture=x86&publicKeyToken=31bf3856ad364e35&versionScope=nonSxS&scope=allUsers\metadata\elements\GDIProcessHandleQuota"
Set WSHShell = CreateObject("WScript.Shell")
Set value = WSHShell.RegRead(strKeyPath)
When run this script its showing me error
WshShell.RegRead: Invalid root in registry key "Schema\wcm://Microsoft-Windows-Win32k-Settings?version=6.1.7600.16385&language=neutral&processorArchitecture=x86&publicKeyToken=31bf3856ad364e35&versionScope=nonSxS&scope=allUsers\metadata\elements\GDIProcessHandleQuota".
Used WMI:
'Constants (taken from WinReg.h)
Const HKEY_CLASSES_ROOT= &H80000000
Const HKEY_CURRENT_USER= &H80000001
Const HKEY_LOCAL_MACHINE= &H80000002
Const HKEY_USERS= &H80000003
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows"
strValueName = "GDIProcessHandleQuota"
oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue
WScript.Echo strValue
Above script showing error "type mismatch".
How should read in correct way or is there any alternative way to iterate through registry and find subkey because i have hardcoded the key that have to avoid. I just want write code like pass GDIProcessHandleQuota so that code will provide value.
I have no idea what the first snippet is trying to do. I have never seen a key path like that before.
But the second code snippet fails with a type mismatch error because GDIProcessHandleQuota is a REG_DWORD value but you are trying to read it as a REG_SZ value. You need to use the StdRegProv.GetDWORDValue() method instead of the StdRegProv.GetStringValue() method.
In any case, you don't need to enumerate the keys in this situation, since the location of GDIProcessHandleQuota is fixed and documented.
For a Test automation I have to check if certain Keys are generated in the registry.
By far I have this script:
'Registry Path
Const HKCR = &H80000000 'HKEY_CLASSES_ROOT (0)
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE (1)
Dim oReg: Set oReg = GetObject("winmgmts:!root/default:StdRegProv")
'Dim Arrays
Dim RegRootArray(1)
Dim RegMachineArray(6)
Dim CurrentArray()
'HKEY_CLASSES_ROOT Array
RegRootArray(0) = "AlmBtPgLib.ALMPlugIn.1\CLSID"
RegRootArray(1) = "AlmBtPgLib.ALMPlugIn\CurVer"
'HKEY_LOCAL_MACHINE Array
RegMachineArray(0) = "SOFTWARE\Macrovision\FlexNet Publisher"
RegMachineArray(1) = "SOFTWARE\Company\SWS\PlugIns\AlmBtPgLib.ALMPlugIn"
RegMachineArray(2) = "SYSTEM\ControlSet001\services\FlexNet Licensing Service"
RegMachineArray(3) = "SYSTEM\CurrentControlSet\services\FlexNet Licensing Service"
RegMachineArray(4) = "SOFTWARE\Company\LMS"
RegMachineArray(5) = "SYSTEM\CurrentControlSet\services\aksfridge"
RegMachineArray(6) = "SYSTEM\CurrentControlSet\services\hasplms"
'Loop through both Arrays and check Registry
For i = 0 To 1
If i=0 Then
ReDim CurrentArray(UBound(RegRootArray)) 'Copy Values from RegRootArray to CurrentArray
For arrI1 = LBound(RegRootArray) To UBound(RegRootArray)
CurrentArray(arrI1) = RegRootArray(arrI1)
Next
Key = HKCR
Else
ReDim CurrentArray(UBound(RegMachineArray)) 'Copy Values from RegMachineArray to CurrentArray
For arrI2 = LBound(RegMachineArray) To UBound(RegMachineArray)
CurrentArray(arrI2) = RegMachineArray(arrI2)
Next
Key = HKLM
End If
'Check Keys in Registry
For Each Path In CurrentArray
If oReg.EnumKey(Key, Path, arrSubKeys) = 0 Then
MsgBox(Path & " exist") 'for development
Else
MsgBox(Path & " don't exist") 'for development
End If
Next
Next
For some reason
"SOFTWARE\Company\SWS\PlugIns\AlmBtPgLib.ALMPlugIn"
is shown as non existing.
I checked if PlugIns or SWS "exists".
None of them do. Company does exist.
I checked the registry and the path manually. Both seem to be okay.
When I create a new Key I can't find it neither.
I restarted the system, no change.
The return value of EnumKey is 2. Simply 2.
I searched the web but couldn't find a solution.
Thanks for your help.
I can't check anything util tomorrow because i leave work for the day.
Update:
When i run the script extern, say as checkReg.vbs it works.
Could it be that UFT somehow has not the right permission? Although both, the .vbs script and UFT run under the same User.
Cheers
sam
In scripting or Visual Basic, the method EnumKey returns an integer value that is 0 (zero) if successful. If the function fails, the return value is a nonzero error code according to Microsoft.
http://msdn.microsoft.com/en-us/library/aa390387%28v=vs.85%29.aspx
Should not you use something like this instead:
Set objReg = Server.CreateObject("WScript.Shell")
RegValue = objReg.RegRead(yourregistryentrypath)
Let's say I have a nethood link to a folder with the name "BLABLA" and the target path is "\\servername\temp"
how do I get the string for the target path?
I tried:
Set oShell = CreateObject("WScript.Shell")
Const NET_HOOD = &H13&
Set oShApp = CreateObject("Shell.Application")
sNetHood = oShApp.NameSpace(NET_HOOD).Self.Path
Set oShortCut = oShell.CreateShortcut(sNetHood & "\" & "BLABLA" & ".lnk")
MsgBox "> " & oShortCut.TargetPath
It does everything, even creates a oShortCut object without any errors.
But, it does not return
oShortCut.TargetPath
what am I doing wrong?
I'd like it to return this: "\\servername\temp\BLABLA"
Thanks in advance for any advice!
I've created the shortcut under win 7 with right click in Computer view of the explorer and then > Add a network location > Next ... etc. It creates a Folder representing a shortcut in NetHood to the path on the server ... it's like a mapped share but not really it.
thx for the input ... after years of reading myself into the matter and then checking google once more i found a c# code which i wrote into vbs and then simplified only to see that all i had to change in the end was to add this:
.GetLink
so the solution to my problem is:
Const NET_HOOD = &H13&
Set oShell = CreateObject("Shell.Application")
Set oFolder = oShell.NameSpace(NET_HOOD)
For Each oFile In oFolder.Items
MsgBox oFile.GetLink.Path
Next
Using the Wscript.Network object shown below, is there an easy way to retrieve the default printer on a machine? I know how to set the default printer, but I'm looking to get the current default printer name. I have a mixture of Windows 2000, XP, and 7 clients and don't want to use WMI for that reason.
Set objNetwork = CreateObject("WScript.Network")
Set objLocalPrinters = objNetwork.EnumPrinterConnections
The WshNetwork.EnumPrinterConnections collection doesn't provide any information about the default printer. You can try retrieving the default printer name from the registry instead, though I'm not sure if it's reliable:
Set oShell = CreateObject("WScript.Shell")
strValue = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"
strPrinter = oShell.RegRead(strValue)
strPrinter = Split(strPrinter, ",")(0)
WScript.Echo strPrinter
As for WMI, it's true that some WMI classes and class members aren't available on older Windows versions. For example, the Win32_Printer.Default property that indicates whether the printer is the default one, doesn't exist on Windows 2000/NT. Nevertheless, there's a simple workaround for finding the default printer on those Windows versions, which consists in checking for the PRINTER_ATTRIBUTE_DEFAULT attribute in each printer's Attribute bitmask:
Const ATTR_DEFAULT = 4
strComputer = "."
Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = oWMI.ExecQuery("SELECT * FROM Win32_Printer")
For Each oPrinter in colPrinters
If oPrinter.Attributes And ATTR_DEFAULT Then
Wscript.Echo oPrinter.ShareName
End If
Next
This code works on later Windows versions as well.
For details, check out this Hey, Scripting Guy! article: Is There Any Way to Determine the Default Printer On a Computer?
From (MSDN):
The EnumPrinterConnections method returns a collection. This collection is an array that associates pairs of items — network printer local names and their associated UNC names. Even-numbered items in the collection represent printer ports. Odd-numbered items represent the networked printer UNC names. The first item in the collection is at index zero (0).
So there is little chance to get the default printer from this collection. Sorry
Greetz,
GHad
for MS ACCESS oPrinter.ShareName is null but oPrinter.Caption works well!
Dim strComputer As String
Dim oWMI As Object
Dim colPrinters
Dim oPrinter
Const ATTR_DEFAULT = 4
strComputer = "."
Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = oWMI.ExecQuery("SELECT * FROM Win32_Printer")
For Each oPrinter In colPrinters
If oPrinter.Attributes And ATTR_DEFAULT Then
Debug.Print oPrinter.Caption
End If
Next
Trying to find the object property for Access to get the default file location so I can script an update to it.
Example: this grabs the stuff from Word and tells me where the user file, and template paths point
Const wdDocumentsPath = 0
Const wdWorkgroupTemplatesPath = 3
Set objWord = CreateObject("Word.Application")
Set objOptions = objWord.Options
Wscript.Echo "Word Documents Path: " & _
objOptions.DefaultFilePath(wdDocumentsPath)
Wscript.Echo "Word Workgroup Templates Path: " & _
objOptions.DefaultFilePath(wdWorkgroupTemplatesPath)
objWord.Quit
Trying to do something similar with Access.
Hmmm ... just having a quick look through the C:\Program Files\Microsoft Office\Office10\MSACC.OLB (I'm using an older Access) using TLViewer.
Property Path As String [Get/o]
member of Access.CodeProject
Property Path As String [Get/o]
member of Access.CurrentProject
Property FullPath As String [Get/o]
member of Access.Reference
I have no idea whether these are useful or not -- I'm not in Access much.
There are two ways to do this. You can, as you suggested, get the Access Object and work with it:
Dim objAcc
Set objAcc = CreateObject("Access.Application")
objAcc.SetOption "Default Database Directory", "C:\Test"
objAcc.Quit
Or you can just edit the value in the registry:
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Access\Settings\Default Database Directory", "C:\Test", "REG_SZ"