WINAMP.COM | Forums > Developer Center > NSIS Discussion > Windows Built-In strings |
| Pages (2): [1] 2 » |
Last Thread
Next Thread
|
| Author |
|
|
Anders Major Dude
Registered: Jun 2002 |
I think you can check the SID or somthing like that and tell who the original admin was __________________ |
||
|
|
|
CancerFace Senior Member
Registered: Apr 2006 |
Thanks for the input Anders, but I do not think that this is what I am after ... If the original account has been renamed all I can get is the new name using its SID. What I need is to find, say in a French version of windows, what is the equivalent of 'Administrator' without asking the system for the administrator's SID (since that SID may point to a renamed account). The same for any other language ... |
||
|
|
|
OldGrumpy Member
Registered: Feb 2006 |
If I remember correctly, the Administrator *ALWAYS* has the same (special, reserved) SID... __________________ |
||
|
|
|
CancerFace Senior Member
Registered: Apr 2006 |
Maybe my initial post was not clear enough … |
||
|
|
|
OldGrumpy Member
Registered: Feb 2006 |
You may want to read this interesting article and the linked resources to get an idea of why your approach seems to be a bad idea __________________ Last edited by OldGrumpy on 05-17-2006 at 12:47 PM |
||
|
|
|
CancerFace Senior Member
Registered: Apr 2006 |
|
||
|
|
|
OldGrumpy Member
Registered: Feb 2006 |
Geez, first of all, why would you need the original name? It isn't useful anymore after the rename. One hint though: if I remember correctly, your "My Files" folder does not change when you rename your account. Dirty hack but probably functional __________________ |
||
|
|
|
Comperio Major Dude
Registered: Jan 2005 |
Taking a step backward here: |
||
|
|
|
CancerFace Senior Member
Registered: Apr 2006 |
|
||
|
|
|
OldGrumpy Member
Registered: Feb 2006 |
I'll post that question to a spe******t board. Let's see what they come up with __________________ |
||
|
|
|
onad Senior Member
Registered: Dec 2004 |
> How do I find the default name of the admin account? Is there a string stored somewhere? __________________ |
||
|
|
|
OldGrumpy Member
Registered: Feb 2006 |
Onad, I did that today on my W2K machine, and couldn't find any suitable occurrences __________________ |
||
|
|
|
CancerFace Senior Member
Registered: Apr 2006 |
Try using PE-Explorer on something like advapi32.dll and you'll see why it wont work |
||
|
|
|
galil Member
Registered: Jan 2003 |
You can simply search for string (both ANSI and Unicode) in multiple files - there's plenty of tools that can do that, (including some of the better text editors) out there, you don't need PEExplorer for that. |
||
|
|
|
CancerFace Senior Member
Registered: Apr 2006 |
galil's suggestion made me look up again inside the system folder, for unicode equivalents of the strings I was after. I finally used UltraEdit to do a unicode search and got all the strings I was after in samsrv.dll. I am not sure if this is what I am after but it is a good start |
||
|
|
|
CancerFace Senior Member
Registered: Apr 2006 |
I think I managed to achieve what I was after, although I cannot check it on another language since I am running an english version of windows. I had to call FormatMessageW twice: the first time I got the size of the message that I extracted and the second time I allocated an appropriate buffer to store it. Since it is a unicode string I don't want to pass it to a variable in NSIS, but leave it at a buffer instead and then pass that buffer to the next function (not shown here)code: I think this should work for every system. The main trick is the usage of the language ID (here I pass it as zero on the 4th parameter of FormatMessage). A better way would be to detect the system default (or the user default) language and then pass it on to the system call. As always any input is welcome ![]() CF |
||
|
|
|
OldGrumpy Member
Registered: Feb 2006 |
I'm very surprised because I though my favorite search tool would be capable of doing unicode searches too. Obviously, it is not __________________ |
||
|
|
|
CancerFace Senior Member
Registered: Apr 2006 |
Hmmm, it may be a bit more complicated after all. By default FormatMessage appends a trailing new line character at the end of the message unless an array of formatting instructions is supplied. And this is where I am lost since this page doesn't make much sense instead of using System::Freecode: quote:I chose that nickname when I was 18 or so and have been using it ever since without realizing most of the time how awful it sounds ... It used to be a joke from a sailing instructor that I had as a kid, and I can assure you that it sounded funny in my mother language (Greek) but certainly not in English ... Nothing to do with my face or any form of cancer, if that's what you're asking ![]() CF [Edit] Looking at the code I posted again I reallized that I am allocating far more space than needed for my buffer. No need to run the FormatMessage function twice, just create the buffer and call the function in one go: code: Last edited by CancerFace on 05-26-2006 at 12:56 PM |
||
|
|
|
OldGrumpy Member
Registered: Feb 2006 |
I think it's worth to expand the functionality and put it into a separate plugin. When I get to have some idle time at my hands, I'll take a shot at it. The code will look much nicer and cleaner when all that formatting stuff is put into a dll. And the string manipulation will become easier, too __________________ |
||
|
|
|
CancerFace Senior Member
Registered: Apr 2006 |
This is tricky. |
||
|
|
|
OldGrumpy Member
Registered: Feb 2006 |
I just had a look at the resources of samsrv.dll and it has no new line char at the end. Did you make sure to create a buffer large enough to carry the wide string and a terminating wide char (zero)? Did you fill the buffer with zeros before using it? It's a common mistake to allocate a buffer and just use it. A call to RtlZeroMemory doesn't take much time but can help a lot __________________ |
||
|
|
|
CancerFace Senior Member
Registered: Apr 2006 |
Check out my previous posts, the whole point is to have the string in a buffer as unicode. The buffer is allocated by the FormatMessage function automatically (I am using ${FORMAT_MESSAGE_ALLOCATE_BUFFER}) so it doesn't really matter what I allocate. I could even use '*(&w1)i.R3' and still the API would expand this, in order to accommodate the string. Not to mention that if I try to allocate the buffer myself (without allowing the API to do so) I don't get anything out. That's why at some point I was calling the function twice so that I would get the string size first, and then allocate a buffer based on that size. |
||
|
|
|
OldGrumpy Member
Registered: Feb 2006 |
From looking at how FormatMessageW works, you have to supply the %0 at the end as wide chars. Did you try that? If you supply the wide char equivalent of "%1%0" as the formatting template to the API, you should get what you want __________________ |
||
|
|
|
CancerFace Senior Member
Registered: Apr 2006 |
code: CF [Edit] I kept forgetting to define $2 and $3 as 0 throughout the thread ... Last edited by CancerFace on 05-27-2006 at 10:31 AM |
||
|
|
|
OldGrumpy Member
Registered: Feb 2006 |
I saw that statement in the docs, too - I just wasn't sure about what it would do. MSDN tends to be cryptic __________________ |
||
|
|
|
CancerFace Senior Member
Registered: Apr 2006 |
I am stuck with this. Although I get the wide string in a buffer, a space is appended at the end and I do not know how to get rid of it. I tried copying the buffer over to a shorter one with no success. I tried setting the size of the buffer before calling FormatMessage (removing the FORMAT_MESSAGE_ALLOCATE_BUFFER parameter and using the 6th parameter to define the buffer size) without any results either. If anyone can see a way out I will appreciate the help |
||
|
|
|
galil Member
Registered: Jan 2003 |
Tried to specify /SIZE for System::Copy? |
||
|
|
|
CancerFace Senior Member
Registered: Apr 2006 |
Without any success. For any size (>2) the whole string with the space at the end is copied over to the new buffer even if the new buffer is allocated in advance: $R9 always contains a space at the end ...code: CF |
||
|
|
|
Afrow UK Moderator
Registered: Nov 2002 |
I guess it would be a good idea to convert it to a plugin as already suggested. There is no API for trimming newlines that I could find on MSDN. __________________ |
||
|
|
|
OldGrumpy Member
Registered: Feb 2006 |
I'll have a look at howto make an NSIS plugin in the next days. I'm quite busy with my job but I think I can find a little time to get it done. __________________ |
||
|
|
|
Afrow UK Moderator
Registered: Nov 2002 |
Well I can do it tomorrow if you'd like me to. __________________ |
||
|
|
|
OldGrumpy Member
Registered: Feb 2006 |
That would be really great __________________ |
||
|
|
|
Afrow UK Moderator
Registered: Nov 2002 |
Any ideas what to call the plugin? __________________ |
||
|
|
|
CancerFace Senior Member
Registered: Apr 2006 |
Wow, I am impressed Now $R3 contains the string with a space at the end and $R4 is the length (in TCHARS) of the string. For the above example, the string is 'Administrator' on my system, and the function reports 14 TCHARS. Is that 13 + 1 (1 being the space)? If yes then I can call the function a second time, only now I will not allow it to allocate the buffer but I will create one and use it:code: The above code does not work however and I am not sure why. The error is 122 (ERROR_INSUFFICIENT_BUFFER).code: Any ideas? CF |
||
|
|
|
Afrow UK Moderator
Registered: Nov 2002 |
I've got the code in a plugin and trimmed the new lines. What do you need to do with the string after that point? __________________ |
||
|
|
|
CancerFace Senior Member
Registered: Apr 2006 |
Thanks a lot by the way Last edited by CancerFace on 05-28-2006 at 10:13 AM |
||
|
|
|
Afrow UK Moderator
Registered: Nov 2002 |
I didn't use FORMAT_MESSAGE_MAX_WIDTH_MASK so there was a \r\n and no space. It isn't possible to pass a string from one plugin to another without storing it in an NSIS variable in between. You'd have to do everything in the same plugin. __________________ |
||
|
|
|
OldGrumpy Member
Registered: Feb 2006 |
What about calling the plugin (Get)SystemMessageStrings? I don't know if with our without "Get" is better __________________ Last edited by OldGrumpy on 05-28-2006 at 11:09 AM |
||
|
|
|
CancerFace Senior Member
Registered: Apr 2006 |
GOT IT!!!!! Now the string is stored in $R2 but if I try to get it out, say usingcode: my program fails. However if I pass this buffer directly to another API it works! Well at least in XP ... Not sure why I am not able to get the string out in $R9 though.code: I passed the buffer to the NetUserAdd API and managed to create a user called 'Administrator' ![]() I will test it in 2k as well and then report back ... CF [Edit] Oups, I was a bit too fast getting excited ![]() It works but the name still contains a space at the end ... It works in 2k as well ... |
||
|
|
|
| Pages (2): [1] 2 » |
Last Thread Next Thread
|
WINAMP.COM | Forums > Developer Center > NSIS Discussion > Windows Built-In strings |
Forum Rules:
|