/build/static/layout/Breadcrumb_cap_w.png

% symbol translation in registry

Dear~

I have one VBscript which writes keys and values in registry.
This VBs file is perfect when it is running alone but when this is inserted into Msi and run by Custom action, it has % symbol translation problem.

<Example>
HKLM\Software\Test_Key
Value Name : Test, Value Data : %1a%source.dat
---> Value Data is written as %%1a%%source.dat with double %

How can I resolve this?
I added VB code to replace %% to % but it doesn't help. (of course, code itself is perfect)

0 Comments   [ + ] Show comments

Answers (6)

Posted by: jib 15 years ago
Purple Belt
0
After my (and everyone's, indeed) initial disclaimer when it comes to this general approach, it would for me at least help a bit if you posted the actual code lines that write to the registry.
Posted by: faithkim 15 years ago
Senior Yellow Belt
0
Hello~.
Thanks for the reminder.

Here is my VBscript. and blue sentence is the problem line.

'----------------------VB Script ------------------------------
Option Explicit
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005

Dim objRegistry, intRC
Dim strKeyPath
Dim strValueName
Dim strcomputer, username, WMIUser
Dim strValue
Dim arrValues
Dim intValue
Dim WSHShell, Regvalue
Dim DomainName, Result
Dim strUserName, strUserDomain
Dim objWMIService, colProcessList, objProcess
Dim My_SID
Dim File_Path

strComputer = "."

'-------------------------Get UserName --------------------
Function GetCurrentUser( )
'Input: strComputer = machine to query
'Input: Current User as domain\logon
'On Error Resume Next
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'explorer.exe'")
For Each objProcess in colProcessList
objProcess.GetOwner strUserName, strUserDomain 'Wscript.Echo strComputer & ",Is logged into by " & strUserDomain & "\" & strUserName
Next
' GetCurrentUser = strUserDomain & "\" & strUserName
GetCurrentUser = strUserName

End Function
'-------------------------Get UserName --------------------
'-------------------------Get SID Name --------------------
Function GetSIDFromUser()
'Input: UserName as domain\logon
'Input: SID

Username = GetCurrentUser()
DomainName = CreateObject("WScript.Network").UserDomain

On Error Resume Next
Set WMIUser = GetObject("winmgmts:{impersonationlevel=impersonate}!" _
& "/root/cimv2:Win32_UserAccount.Domain='" & DomainName & "'" _
& ",Name='" & UserName & "'")
If Err = 0 Then Result = WMIUser.SID Else Result = ""
On Error GoTo 0

GetSIDFromUser = Result

End Function
'-------------------------Get SID Name --------------------
My_SID = GetSIDFromUser
set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
Set WSHShell = CreateObject("WScript.Shell")

strKeyPath = "HKEY_USERS\" & My_SID & "\Software\Microsoft\Speech\CurrentUserLexicon\{C9E37C15-DF92-4727-85D6-72E5EEB6995A}\Files\"
WSHShell.RegWrite strKeyPath & "Datafile", "%1a%\Microsoft\Speech\Files\UserLexicons\SP_99DCCA6823604DA1BC1CAEC25972EFBE.dat"
IntRc = objRegistry.CreateKey(HKEY_USERS, strKeyPath)

-------------------------------------------------------------------------

and this script is run by CA.
My CA use dos command "cmd.exe" to run the script in INSTALLDIR after "WriteRegistryValues", Asyncronos(No wait for completion), immediate action.

cmd /c "[INSTALLDIR]SET_SID.vbs"
Posted by: anonymous_9363 15 years ago
Red Belt
0
- Use the 'code' tags when submitting, er, code: it makes scroling easier. Click the '<%' button just above the text area.
- Does the script work external to the MSI? I'm struggling with the lines in blue as you seem to be attempting to write a vlue before the key is created.
- Why bother with getting the user's SID and so on, when you could execute the script in User context?
- Ditch using CMD.EXE, it just adds complication. Call CSCRIPT.EXE directly and Windows will open a comnmand prompt anyway. If you're bothered about windows opening and such, you can pass parameters to Shell.Run or use another execution method e.g. ShellExecute.

Coming to the actual issue, I suspect that you have lifted the value directly from a capture. The string you have makes no sense. Find out what the actual value is. I suspect, given the structure of the remainder of the registry key, that it probably refers to the hive, not a key. I further suspect that it's simply HKEY_CURRENT_USER.
Posted by: jib 15 years ago
Purple Belt
0
ORIGINAL: VBScab
I suspect, given the structure of the remainder of the registry key, that it probably refers to the hive, not a key. I further suspect that it's simply HKEY_CURRENT_USER.


Yes it does refer to the hive :-) I wondered why he's doing this also, seems a bit strange, but I tried to "respect the original question" hehe. It might have value if you think about it, "current user" could be the account msiexec is running as, and that might not be what's desired.

I haven't actually tried to write a %-sign to the registry from a CA like described yet, have you VB?
Posted by: anonymous_9363 15 years ago
Red Belt
0
ORIGINAL: jib
I haven't actually tried to write a %-sign to the registry from a CA like described yet, have you VB?
Never SEEN one, much less tried to write one :)
Posted by: faithkim 15 years ago
Senior Yellow Belt
0
Thanks for the advice. you guys are right....

As a biggner who doesn't know the registry, vbscript and packaging well... you guys' advice make me feel a bit bad [:(]

However I learned more.

As you commented, I looked at current_user hive and found that the registry value was wrong there with double % --> this is wrongly captured by repackager.

and before unfortunately I tried to fix Hkey_users(SID) using VB.
After all, I just fixed Current_User key only and it worked fine.

Many Thanks.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ