Jump to content

Embedding a variable within a string


DeFuser
 Share

Recommended Posts

Hello all,

I am running into what I think (hope) is a small syntax issue, but it is driving me nuts regardless.

I am trying to tweak the Windows registry to force all of our users into cached Exchange mode. The specific user name is part of the key snippet shown below:

... \CurrentVersion\Windows Messaging Subsystem\Profiles\$username\13dbb0c8aa05101 ...

I am using the RegWrite function. Unfortunately, I can not figure out how to incorporate the variable $username into the string required by RegWrite. Using MsgBox as an example (to keep things easy to read), I am trying to pull off the following:

$age = "22"

MsgBox(64,"FYI -", "You are " & $age "years old.", 5)

"Your age in years is " & $age" is easy enough to do, but I have been nothing but (very) unsuccessful at putting the variable in the middle. I have tried various combinations of single quotes, double quotes, and ampersands to no avail.

The fact that I haven't been able to find any documentation or examples of this leads me to think that I am barking up the wrong tree, but I don't have a clue as to the work-around. Then again I am surprised that nobody else has posted about this problem ... Hmm, maybe I'm just st00pid!

Cheers and thanks,

Def

Link to comment
Share on other sites

MsgBox(64,"FYI -", "You are " & $age & " years old.", 5)

Oh, how I wish it were that easy! Believe me, I really have tried to make this work - Including the double ampersand method you suggest. Mind you that I have been mucking with the RegWrite command, but I figured that the solution would be the same for RegWrite and MsgBox and used the MsgBox example for clarity. My actual (and quite ugly) line is:

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\username\13dbb0c8aa05101a9bb000aa002fc45a", "00036601", "REG_BINARY", "04000000")

I appreciate the quick response though!

Cheers,

Def

Link to comment
Share on other sites

$username = @UserName

;RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\username\13dbb0c8aa05101a9bb000aa002fc45a", "00036601", "REG_BINARY", "04000000")


MsgBox(64, "Test", "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\" & $username &"\13dbb0c8aa05101a9bb000aa002fc45a")

8)

NEWHeader1.png

Link to comment
Share on other sites

Defuser,

I am a total noob, but I got very confused by these middle variable things today and here's what I came up with to help clear things up for me - maybe it will help you - it will most likely scare the rest of you :lmao:

Of course, the code assumes that $user is your username variable, and I remarked out the RegWrite line, but I left the message box so you could see the output.

$Beg = """HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\"
$mid = $user
$End = "\13dbb0c8aa05101a9bb000aa002fc45a"" "


MsgBox(0, "Test", $Beg & $Mid & $End)
;RegWrite($Beg & $Mid & $End, "00036601", "REG_BINARY", "04000000")
Edited by MuffinMan
Link to comment
Share on other sites

;)

Valuater. your solution did indeed work. Matter of fact, it worked in both instances. I used the trusty copy-n-paste on your first example and (quite to my astonishment) it worked perfectly. I then manually entered the RegWrite line (paying close attention to entering the problem section exactly as you presented it)xs and it worked the very first time - without a hitch - right out of the box even!

I have yet to figure out what I was doing wrong, but I have a suspicion that the compiler is more sensitive to spaces than I thought it was. The good news is that I now know that it can be done and I also know how to do it.

So once again, I'd like to thank you - Twice even. And by all means feel free to enjoy knowing that you solved in a few minutes what frustrated me for a few hours.

Best wishes,

A very happy Def

SlimJim - Thanks for your input too :lmao:

Link to comment
Share on other sites

;)

Valuater. your solution did indeed work. Matter of fact, it worked in both instances. I used the trusty copy-n-paste on your first example and (quite to my astonishment) it worked perfectly. I then manually entered the RegWrite line (paying close attention to entering the problem section exactly as you presented it)xs and it worked the very first time - without a hitch - right out of the box even!

I have yet to figure out what I was doing wrong, but I have a suspicion that the compiler is more sensitive to spaces than I thought it was. The good news is that I now know that it can be done and I also know how to do it.

So once again, I'd like to thank you - Twice even. And by all means feel free to enjoy knowing that you solved in a few minutes what frustrated me for a few hours.

Best wishes,

A very happy Def

SlimJim - Thanks for your input too :lmao:

That was really nice, most people don't even say "thanks"....

comments like that make all of the Helping people here at AutoIt, like myself, Want to help others

8)

NEWHeader1.png

Link to comment
Share on other sites

;)

Valuater. your solution did indeed work. Matter of fact, it worked in both instances. I used the trusty copy-n-paste on your first example and (quite to my astonishment) it worked perfectly. I then manually entered the RegWrite line (paying close attention to entering the problem section exactly as you presented it)xs and it worked the very first time - without a hitch - right out of the box even!

I have yet to figure out what I was doing wrong, but I have a suspicion that the compiler is more sensitive to spaces than I thought it was. The good news is that I now know that it can be done and I also know how to do it.

So once again, I'd like to thank you - Twice even. And by all means feel free to enjoy knowing that you solved in a few minutes what frustrated me for a few hours.

Best wishes,

A very happy Def

SlimJim - Thanks for your input too :lmao:

[ old code]

$age = "22"

MsgBox(64,"FYI -", "You are " & $age "years old.", 5)

[ /old code]

I think your problem all along was simply that you forgot the other & after the $age. Honestly, I think that was the only problem (you did mention that you tried that method already, so I'm not sure how that didn't work).

@MuffinMan:

$Beg = """HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\"
$mid = $user
$End = "\13dbb0c8aa05101a9bb000aa002fc45a"" "


MsgBox(0, "Test", $Beg & $Mid & $End)
;RegWrite($Beg & $Mid & $End, "00036601", "REG_BINARY", "04000000")

It would probably be easier for you to use both single and double quotations when you need to enclose the string in quotes. In other words, ' " ' instead of " " " (both do the same thing, one is just a little easier to read in my opinion).

Link to comment
Share on other sites

I think your problem all along was simply that you forgot the other & after the $age. Honestly, I think that was the only problem (you did mention that you tried that method already, so I'm not sure how that didn't work).

Hey all, I really want to say thanks for all of the input and assistance. I was digging through one of my testing phase .au3 files and found the following:

... Subsystem\Profiles\" & $username &"\13dbb0c8aa05101a9bb...

I am thinking that it wasn't the second ampersand that got me; it was the spaces. Methinks that I was thinking of the "&" as continuation character. I probably tried (along with various combinations and omissions of single and double quotes):

" & $username &"

" &$username& "

"& $username &"

"& $username & "

And to think that I was so close! I kid you not, I toyed with this (and with potential work-arounds) for hours. I actually had myself thinking that "there must be some other command for instances like this." The bright side is that hopefully you guys who are familiar with this stuff will at least get a chuckle out of it.

Hey, how do I make a contribution to the .chm file? :lmao:

Cheers,

Def

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...