Jump to content

Create shortcuts for startmenu silently, must work on all WinXP langua


Recommended Posts

I'm back from field investigation! Here are the result:

DISCLAIMER: I do also think that inf or vbs syntax may be more appropriate for the orginal question. Please consider the following as a game proof of concept only.

1- windows (ANSI) code page (my 1252 above) is stored there:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage]
"ACP"="1252"

If ever you want to experiment and change it, do NOT do it directly in the registry. Use instead: Control Panel / Regional & Language Settings / Advanced Tab /Language for Non Unicode Programs dropdown. Once clicking OK, answer yes to bul***** dialog and yes to reboot. Back to 1252 the same way.

Anyway to complete Delprat's patch, we should now write:

FOR /F "tokens=2 delims=:" %%c IN ('CHCP') DO SET CodeP=%%c
FOR /F "skip=4 tokens=3 delims= " %%? IN ('REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage" /V "ACP"') DO (CHCP %%?)
FOR /F "skip=4 tokens=3 delims= " %%? IN ('
REG QUERY "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /V "Common Startup"
') DO (CHCP%CodeP%&& SET Startup=%%?)

2- To doublecheck that querying the registry was working for every language, I inserted a value with japanese data in the registry and changed my code pages to japanese as shown above. Note that japanese code page, 932, is the same for ANSI (windows) and OEM (cmd.exe) so no need for the CHCP trick described above.

I then reg queried my value, which displayed fine.

Then I did the FOR trick to keep only the data in a variable. And there, BADABOUM ! :huh:

The value was truncated:日本語が分か instead of the full 日本語が分かるんですか。

So I tried different technics to grab the value correctly, all but one to no avail. Same was true about French accent (if not using the CHCP trick above). Below is the output (french version, japanese attached) from a test batch (see attachement) implementing the different techniques one after the other:

REFERENCE:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders]

value type data:

Common Startup REG_SZ C:\Documents and Settings\All Users\Menu Démarrer\Programmes\Démarrage

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

0- REG QUERY command (full) result:

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

! REG.EXE VERSION 3.0

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders

Common Startup REG_SZ C:\Documents and Settings\All Users\Menu Démarrer\Programmes\Démarrage

1- FIND command on REG QUERY result:

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

Common Startup REG_SZ C:\Documents and Settings\All Users\Menu DÚmarrer\Programmes\DÚmarrage

2- Redirection of REG QUERY to file:

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

Common Startup REG_SZ C:\Documents and Settings\All Users\Menu DÚmarrer\Programmes\DÚmarrage

3- FOR loop on the REG QUERY result:

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

Common Startup REG_SZ C:\Documents and Settings\All Users\Menu DÚmarrer\Programmes\DÚmarrage

4- FOR loop on the REG EXPORT file:

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

5- FOR loop on TYPE REG EXPORT file:

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

Common Startup REG_SZ C:\Documents and Settings\All Users\Menu Démarrer\Programmes\Démarrage

-> As you can see, as soon as manipulated in any way, REG QUERY result got corrupted. I don't know if REG and CMD are different in Japan.

-> I don't know exactly why, but I could not read the REG EXPORT file directly in the FOR loop. Probably because it is in unicode.

-> I had to TYPE it and do the FOR on that. And only then, the result was correct.

It means that who ever absolutely needs to use and internationalized registry value in a batch should use the following syntax:

SETLOCAL ENABLEDELAYEDEXPANSION
REG EXPORT "%KEY%" "%FILE%" >nul
FOR /F "skip=2 tokens=1* delims==" %%I IN ('TYPE "%FILE%"') DO (
SET TEST=%%I
::We don't want to pick values in subkeys
IF "!TEST:~0,1!"=="[" (IF "!TEST:%KEY%=!" NEQ "[]" GOTO ENDFOR)
IF "!TEST:~1,-1!"=="%VALUE%" (SET DATA=%%J)
)
:ENDFOR
SET DATA=!DATA:~1,-1!& SET DATA=!DATA:\\=\!

This seems to be robust because:

-REG EXPORT calls regedit32 to do the job, which is done in Unicode.

-TYPE can read Unicode (if it has the good code page) much better than ANSI, as it seems.

3- Ok, now it would be interesting to know if that technique is really working for our actual purpose and could be used specifically for placing last-minute tweaks in the startup folder, whatever language is set on the computer.

The last attached file is a test batch that, if successful, would place another batch in the startup folder (Start menu / Programs / Startup). If you are interested to know if such a trick can work in your language, download & run it, and then look in your startup folder if you see it. Please, report about it here so others can benefit from your experience.

result_jp_unicode.txt

full_test.cmd

startup_test.cmd

Edited by Djé
Link to comment
Share on other sites


wow you've been busy! :lol:

I was playing with INF, I now fully understand how to create Shortcuts this way and I like it :)

But need some help on this... it annoys me:

(btw, it creates shortcuts for All users Start Menu and 16422 = %programfiles%)

[Version]
Signature = $Windows NT$


[DefaultInstall]
ProfileItems = easyGuide,dvdFab,dvd-Rb


[easyGuide]
Name = EasyGuide
CmdLine = 16422,DVD-ReBuilder,"DVD-Rebuilder EasyGuide.pdf"
SubDir= Copy DVD movies

[dvdFab]
Name = "[1] rip a DVD movie"
CmdLine = 16422,"DVDFab Decrypter",DVDFabDecrypter.exe
SubDir= Copy DVD movies
InfoTip = "STEP 1: Copy a DVD-movie to your harddrive, removing(decrypt) the dvd-protection"

[dvd-Rb]
Name = "[2] rebuild a DVD movie"
CmdLine = 16422,"DVD-ReBuilder",Rebuilder.exe
SubDir= Copy DVD movies
InfoTip = "STEP 2: Rebuild a DVD-movie to fit on a DVD-/+R"

This works fine EXCEPT [easyGuide]!

The shortcut IS created, but doesn't work because this is what the path looks like:

"C:\Program Files\DVD-ReBuilder\DVD-Rebuilder" EasyGuide.pdf

Instead of

"C:\Program Files\DVD-ReBuilder\DVD-Rebuilder EasyGuide.pdf"

I tried playing with the " but didn't do any good! How come?

INF can't work with spaces in the commandfile?

ofcourse renaming the PDF without the space would solve it, but I think it must be possible.

EDIT:

Ok have been messing around with my INF some more! :)

Still don't have a solution for the problem described. Did found some new obstacles... jumped over all of them except these 2:

- Is it correct with INF you cannot delete folders? only files :(

- Also, there is no MoveFiles option, only CopyFiles! This means, if I want to move files (for example: from a tempdir to their destination) I have to write a CopyFiles and aDelFiles to delete them after copying :S

Can't believe INF is that inefficient!

Edited by ZileXa
Link to comment
Share on other sites

@ Djé > wow... impressing ! all these CHCP killed by a REG EXPORT + TYPE...

@ ZileXa >

1/ The space in the CmdLine of the shortcut is interpreted by the INF parser as a separator between the excutable and its parameters. So you only need to link to Adobe Reader with your pdf as a parameter :

[easyGuide]
Name = EasyGuide
CmdLine = 16422,"Adobe\Acrobat 7.0\Reader","AcroRd32.exe ""%16422%\DVD-ReBuilder\DVD-Rebuilder EasyGuide.pdf"""
IconPath=16422,"Adobe\Acrobat 7.0\Reader",AcroRd32.dll
IconIndex=2
SubDir= Copy DVD movies

(bonus: the "pdf file" icon instead of the "adobe reader" one)

2/ INF can delete folders in some cases. Here you go : click (the keywords are highlighted, in case you want to check if the "search" feature of the forum is working :D )

3/ Yes, there's no MoveFiles. There's RenFiles, CopyFiles and DelFiles ; and these 3 allow all possible file operations.

4/ Yes, INF are totally inefficient... So you'll learn VBS, and you'll see that VBS syntax is toooooooo heaaaaaavyyyyyyyyyyyy... So you'll learn C++ and you'll se that Windows API is soooooo buuuugggggyyyyyyyyy.... So you'll switch to linux (and i'll stop trolling)

Edited by Delprat
Link to comment
Share on other sites

Thanks for clearing that up! But then I prefer renaming the PDF file without a space, because not everyone uses Adobe Reader... thats like using a heavy truck to transport a pizza, instead of using a motorcycle :P

Some people use Foxit Reader.

Actually, I found there IS a Movefiles feature, and a Deletefolders feature not using advpack... see here:

http://www.msfn.org/board/index.php?showtopic=10176&st=30

using Rundll32 commands :)

Edited by ZileXa
Link to comment
Share on other sites

You're welcome...

About Foxit : yes, i know... see my 4th point ;)

Suggestions :

- replace Adobe Reader by a "ShellExecute wrapper" : ShellExecute is a Win32 API that can "run the associated program" (in other words, it behave as if you had doubleclicked on it). There's StartX.exe on this forum ; and also NirCmd from NirSoft.net. Example with StartX (in %windir%) :

CmdLine = 10,,"StartX.exe ""%16422%\DVD-ReBuilder\DVD-Rebuilder EasyGuide.pdf"""

Avantage : will work no matter of the "preferred PDF viewer"

Drawback : you'll loose that super icon

- fool the INF parser by using another space, i mean the Alt+0160 or Alt+255 magic combo instead of the real space (both in the file name and the INF file, of course)

Avantage : you'll get the correct icon

Drawback : you will forget about that and loose many hours before remembering which of the two magic combos you used :P

About the RunDLL commands for moving a file or deleting a directory...hell...thats like using a heavy truck to transport a pizza, instead of using a motorcycle :P

Some people uses batch files, even to make shortcuts :lol::yes: (look... you can even call your batch with an inf...)

Edited by Delprat
Link to comment
Share on other sites

LOL

hehe, I was just so amazed about the power of INF... thought it was waaay better then CMD...

and now that I learned it fast I don't wanna go back to CMD... INF still has the advantage it will work on every version of Windows, no matter what language. For CMD, this becomes very difficult, I still didn't test Dje's final code in his 3/april post.

Well before a new version of one of the programs in my Easy Installer pack is released I have to make up my mind :)

I will post final result here and test Dje's code soon... actually have to start learning for my exams next week but this INF and CMD and also VBS.. it is quite interesting, well actually it is not but one can do lots of interesting things with it. AutoIt is also nice btw :D

Edited by ZileXa
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
  • Recently Browsing   0 members

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