Jump to content

Need help to change the default program for .java files


Recommended Posts

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.exe

I 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 Explicit
Dim objShell
set objShell = WScript.CreateObject ("WScript.Shell")

addFileAssociation ".java", "C:\Program Files (x86)\Ready to Program\Ready.exe"

Sub addFileAssociation( fileExt, whichApp )
If ( Left(fileExt, 1) <> "." ) Then
fileExt = "." & fileExt
End If
objShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & fileExt & "\Application", whichApp
End Sub

Link to comment
Share on other sites


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? :unsure:

http://ss64.com/nt/assoc.html

http://ss64.com/nt/ftype.html

http://ss64.com/nt/associate.html

jaclaz

I 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-vbs

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.

Link to comment
Share on other sites

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.aspx

ListFileAssociations.vbs

Set objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K Assoc | more"), 1, True

ChangeFileAssociation.vbs

Set objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K ftype TIFImage.Document =""C:\Program Files\MSPVIEW.exe"" ""%1"""), 1, True

Afaik, 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.html

Which BTW "justifies" the otherwise senseless:

If ( Left(fileExt, 1) <> "." ) Then

fileExt = "." & fileExt

End If

If 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.html

jaclaz

Link to comment
Share on other sites

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.aspx

ListFileAssociations.vbs

Set objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K Assoc | more"), 1, True

ChangeFileAssociation.vbs

Set objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K ftype TIFImage.Document =""C:\Program Files\MSPVIEW.exe"" ""%1"""), 1, True

Afaik, 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.html

Which BTW "justifies" the otherwise senseless:

If ( Left(fileExt, 1) <> "." ) Then

fileExt = "." & fileExt

End If

If 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.html

jaclaz

Thanks Jaclaz,

You are saying to do this, i am sorry I am really not skilled in vbs. Do this

Option Explicit
Dim objShell
Set 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 by clivebuckwheat
Link to comment
Share on other sites

You need a newline:

Option Explicit
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 1, True

This snippet assumes that a filetype "java.Document" already exists (and is associated to the .java extension)

jaclaz

Link to comment
Share on other sites

Thank Jaclaz,

Option Explicit
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 1, True

Unfortunately the above still refuses to change, the .java extension to open in Ready to Program.

Edited by clivebuckwheat
Link to comment
Share on other sites

How can I make the .java association exist first?

Using ASSOC ! :realmad: back to square #1, actually post #2 (and given links).

assoc .java=java.Document

This should do :unsure:

Option Explicit
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K assoc.java=java.Document "), 1, True
objShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 1, True

jaclaz

Link to comment
Share on other sites

How can I make the .java association exist first?

Using ASSOC ! :realmad: back to square #1, actually post #2 (and given links).

assoc .java=java.Document

This should do :unsure:

Option Explicit
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K assoc.java=java.Document "), 1, True
objShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 1, True

jaclaz

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.

Link to comment
Share on other sites

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 :w00t:

Use NIRCMD:

http://www.nirsoft.net/utils/nircmd.html

though 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#using

Or 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.aspx

http://superuser.com/questions/62525/run-a-completly-hidden-batch-file

Apart 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

You do not need any 3rd party application to run a vbs script without showing any Cmd Window.

Show Window


Option Explicit
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K assoc.java=java.Document "), 1, True
objShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 1, True

Hide Window


Option Explicit
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K assoc.java=java.Document "), 0, True
objShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 0, True

Another 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

  • 2 weeks later...

You do not need any 3rd party application to run a vbs script without showing any Cmd Window.

Show Window


Option Explicit
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K assoc.java=java.Document "), 1, True
objShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 1, True

Hide Window


Option Explicit
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K assoc.java=java.Document "), 0, True
objShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 0, True

Another 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

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...