clivebuckwheat Posted September 16, 2012 Share Posted September 16, 2012 Hi I have to change the default program for .java files it should open by default in a program called Ready to Program which is available here. http://compsci.ca/holtsoft/ready171_install.exeI tried the following vbs script but it isn't working.Any help would be greatly appreciated as I have to make this the default on about 250 computers,Option ExplicitDim objShellset objShell = WScript.CreateObject ("WScript.Shell")addFileAssociation ".java", "C:\Program Files (x86)\Ready to Program\Ready.exe"Sub addFileAssociation( fileExt, whichApp )If ( Left(fileExt, 1) <> "." ) ThenfileExt = "." & fileExtEnd IfobjShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & fileExt & "\Application", whichAppEnd Sub Link to comment Share on other sites More sharing options...
jaclaz Posted September 16, 2012 Share Posted September 16, 2012 Where did you get that snippet?Particularly, where did you get the Registry path?HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\Any reason NOT to use the ASSOC/FTYPE/ASSOCIATE commands? http://ss64.com/nt/assoc.htmlhttp://ss64.com/nt/ftype.htmlhttp://ss64.com/nt/associate.htmljaclaz Link to comment Share on other sites More sharing options...
clivebuckwheat Posted September 16, 2012 Author Share Posted September 16, 2012 Where did you get that snippet?Particularly, where did you get the Registry path?HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\Any reason NOT to use the ASSOC/FTYPE/ASSOCIATE commands? http://ss64.com/nt/assoc.htmlhttp://ss64.com/nt/ftype.htmlhttp://ss64.com/nt/associate.htmljaclazI got the code from stack over flow. here is the snippet of code.http://stackoverflow.com/questions/7988655/proper-way-tho-change-file-associations-using-vbsI have never had any luck with the assoc commands, and I would like to use vbs, so I could just append the file associate fix into my default printer.vbs that runs in the startup of all the computers. Link to comment Share on other sites More sharing options...
jaclaz Posted September 16, 2012 Share Posted September 16, 2012 I have never had any luck with the assoc commands, and I would like to use vbs, so I could just append the file associate fix into my default printer.vbs that runs in the startup of all the computers.Try these:http://blogs.technet.com/b/heyscriptingguy/archive/2009/03/27/quick-hits-friday-the-scripting-guys-respond-to-a-bunch-of-questions-03-27-09.aspxListFileAssociations.vbsSet objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K Assoc | more"), 1, TrueChangeFileAssociation.vbsSet objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K ftype TIFImage.Document =""C:\Program Files\MSPVIEW.exe"" ""%1"""), 1, TrueAfaik, a file association has a number of related keys in HKEY_CLASSES_ROOT (that the built-in commands know how to manage).The snippet you posted most probably originated (without credits) from here:http://jimkeller.blogspot.it/2005/09/changing-file-associations-in-windows.htmlWhich BTW "justifies" the otherwise senseless:If ( Left(fileExt, 1) <> "." ) ThenfileExt = "." & fileExtEnd IfIf you hardcoded .java, there is no need to check if the first character is a dot.... This might be useful to quickly check associations:http://www.nirsoft.net/utils/file_types_manager.htmljaclaz Link to comment Share on other sites More sharing options...
clivebuckwheat Posted September 16, 2012 Author Share Posted September 16, 2012 (edited) I have never had any luck with the assoc commands, and I would like to use vbs, so I could just append the file associate fix into my default printer.vbs that runs in the startup of all the computers.Try these:http://blogs.technet.com/b/heyscriptingguy/archive/2009/03/27/quick-hits-friday-the-scripting-guys-respond-to-a-bunch-of-questions-03-27-09.aspxListFileAssociations.vbsSet objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K Assoc | more"), 1, TrueChangeFileAssociation.vbsSet objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K ftype TIFImage.Document =""C:\Program Files\MSPVIEW.exe"" ""%1"""), 1, TrueAfaik, a file association has a number of related keys in HKEY_CLASSES_ROOT (that the built-in commands know how to manage).The snippet you posted most probably originated (without credits) from here:http://jimkeller.blogspot.it/2005/09/changing-file-associations-in-windows.htmlWhich BTW "justifies" the otherwise senseless:If ( Left(fileExt, 1) <> "." ) ThenfileExt = "." & fileExtEnd IfIf you hardcoded .java, there is no need to check if the first character is a dot.... This might be useful to quickly check associations:http://www.nirsoft.net/utils/file_types_manager.htmljaclazThanks Jaclaz,You are saying to do this, i am sorry I am really not skilled in vbs. Do thisOption ExplicitDim objShellSet objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 1, True Edited September 16, 2012 by clivebuckwheat Link to comment Share on other sites More sharing options...
jaclaz Posted September 16, 2012 Share Posted September 16, 2012 You need a newline:Option ExplicitDim objShellSet objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 1, TrueThis snippet assumes that a filetype "java.Document" already exists (and is associated to the .java extension)jaclaz Link to comment Share on other sites More sharing options...
clivebuckwheat Posted September 16, 2012 Author Share Posted September 16, 2012 (edited) Thank Jaclaz,Option ExplicitDim objShellSet objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 1, TrueUnfortunately the above still refuses to change, the .java extension to open in Ready to Program. Edited September 16, 2012 by clivebuckwheat Link to comment Share on other sites More sharing options...
clivebuckwheat Posted September 18, 2012 Author Share Posted September 18, 2012 Jaclaz,I did an assoc .javait seems there is no association for the .java extension, so that is why the above vbs script will not work. How can I make the .java association exist first?Thanks for the help. I really do appreciated. Link to comment Share on other sites More sharing options...
jaclaz Posted September 18, 2012 Share Posted September 18, 2012 How can I make the .java association exist first?Using ASSOC ! back to square #1, actually post #2 (and given links).assoc .java=java.DocumentThis should do Option ExplicitDim objShellSet objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K assoc.java=java.Document "), 1, TrueobjShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 1, Truejaclaz Link to comment Share on other sites More sharing options...
clivebuckwheat Posted September 18, 2012 Author Share Posted September 18, 2012 How can I make the .java association exist first?Using ASSOC ! back to square #1, actually post #2 (and given links).assoc .java=java.DocumentThis should do Option ExplicitDim objShellSet objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K assoc.java=java.Document "), 1, TrueobjShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 1, TruejaclazThank you Jaclaz it now changes the association, I could have swore I ran the assoc command. Sorry. One more question about the above vbscript. Would it be possible to suppress the cmd window?. I need it totally silent as I am going to put it in the startup of my computers.Thanks again you been an amazing help. Link to comment Share on other sites More sharing options...
jaclaz Posted September 18, 2012 Share Posted September 18, 2012 Thank you Jaclaz it now changes the association, I could have swore I ran the assoc command. Sorry. One more question about the above vbscript. Would it be possible to suppress the cmd window?. I need it totally silent as I am going to put it in the startup of my computers.Thanks again you been an amazing help.Which brings us back to square #1 on a few other thread Use NIRCMD:http://www.nirsoft.net/utils/nircmd.htmlthough NOT the answer to all questions (as an example the Answer to the ultimate question about life, the universe and everything is instead 42 ) it does represent an answer to most common day problems where bathc is involved.exec hide, exec2 hide or execmd might be what you need:http://www.nirsoft.net/utils/nircmd2.html#usingOr use any of the various alternative approaches:http://blogs.technet.com/b/heyscriptingguy/archive/2007/12/05/hey-scripting-guy-how-can-i-start-a-script-in-a-hidden-window.aspxhttp://superuser.com/questions/62525/run-a-completly-hidden-batch-fileApart for the "pure .vbs" ones, the Iexpress one could be handy. Thanks again you been an amazing help.No prob .jaclaz Link to comment Share on other sites More sharing options...
gunsmokingman Posted September 18, 2012 Share Posted September 18, 2012 You do not need any 3rd party application to run a vbs script without showing any Cmd Window.Show WindowOption ExplicitDim objShellSet objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K assoc.java=java.Document "), 1, TrueobjShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 1, TrueHide WindowOption ExplicitDim objShellSet objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K assoc.java=java.Document "), 0, TrueobjShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 0, TrueAnother Example Hidden Window that produces a text file with no Window Showing CreateObject("Wscript.Shell").Run(_ "%Comspec% /C @Echo Off && CLS && Echo Test Line 1 > Test.txt && " & _ "Ping -n 2 127.0.0.1>nul && Echo Test Line 2 >> Test.txt"),0,True Link to comment Share on other sites More sharing options...
clivebuckwheat Posted September 30, 2012 Author Share Posted September 30, 2012 You do not need any 3rd party application to run a vbs script without showing any Cmd Window.Show WindowOption ExplicitDim objShellSet objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K assoc.java=java.Document "), 1, TrueobjShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 1, TrueHide WindowOption ExplicitDim objShellSet objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K assoc.java=java.Document "), 0, TrueobjShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 0, TrueAnother Example Hidden Window that produces a text file with no Window Showing CreateObject("Wscript.Shell").Run(_ "%Comspec% /C @Echo Off && CLS && Echo Test Line 1 > Test.txt && " & _ "Ping -n 2 127.0.0.1>nul && Echo Test Line 2 >> Test.txt"),0,True Thanks man. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now