MSFN Forum: Need help to change the default program for .java files - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Need help to change the default program for .java files Rate Topic: -----

#1 User is offline   clivebuckwheat 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 562
  • Joined: 07-November 05

Posted 16 September 2012 - 09:33 AM

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/ho...171_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




#2 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,578
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 16 September 2012 - 09:43 AM

Where did you get that snippet?
Particularly, where did you get the Registry path?

View Postclivebuckwheat, on 16 September 2012 - 09:33 AM, said:

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

#3 User is offline   clivebuckwheat 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 562
  • Joined: 07-November 05

Posted 16 September 2012 - 09:55 AM

View Postjaclaz, on 16 September 2012 - 09:43 AM, said:

Where did you get that snippet?
Particularly, where did you get the Registry path?

View Postclivebuckwheat, on 16 September 2012 - 09:33 AM, said:

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

#4 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,578
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 16 September 2012 - 10:11 AM

View Postclivebuckwheat, on 16 September 2012 - 09:55 AM, said:

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...s-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.blo...in-windows.html
Which BTW "justifies" the otherwise senseless:

Quote

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.n...es_manager.html

jaclaz

#5 User is offline   clivebuckwheat 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 562
  • Joined: 07-November 05

Posted 16 September 2012 - 10:49 AM

View Postjaclaz, on 16 September 2012 - 10:11 AM, said:

View Postclivebuckwheat, on 16 September 2012 - 09:55 AM, said:

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...s-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.blo...in-windows.html
Which BTW "justifies" the otherwise senseless:

Quote

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


This post has been edited by clivebuckwheat: 16 September 2012 - 10:51 AM


#6 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,578
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 16 September 2012 - 11:07 AM

You need a newline:

View Postclivebuckwheat, on 16 September 2012 - 10:49 AM, said:

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

#7 User is offline   clivebuckwheat 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 562
  • Joined: 07-November 05

Posted 16 September 2012 - 01:26 PM

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.

This post has been edited by clivebuckwheat: 16 September 2012 - 03:18 PM


#8 User is offline   clivebuckwheat 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 562
  • Joined: 07-November 05

Posted 18 September 2012 - 07:33 AM

Jaclaz,

I did an assoc .java

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

#9 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,578
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 18 September 2012 - 08:20 AM

View Postclivebuckwheat, on 18 September 2012 - 07:33 AM, said:

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

#10 User is offline   clivebuckwheat 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 562
  • Joined: 07-November 05

Posted 18 September 2012 - 09:20 AM

View Postjaclaz, on 18 September 2012 - 08:20 AM, said:

View Postclivebuckwheat, on 18 September 2012 - 07:33 AM, said:

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.

#11 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,578
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 18 September 2012 - 10:14 AM

View Postclivebuckwheat, on 18 September 2012 - 09:20 AM, said:

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.n...ils/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.n...cmd2.html#using

Or use any of the various alternative approaches:
http://blogs.technet...den-window.aspx
http://superuser.com...dden-batch-file
Apart for the "pure .vbs" ones, the Iexpress one could be handy.

View Postclivebuckwheat, on 18 September 2012 - 09:20 AM, said:

Thanks again you been an amazing help.

No prob :).

jaclaz

#12 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,356
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 18 September 2012 - 10:31 AM

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 



#13 User is offline   clivebuckwheat 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 562
  • Joined: 07-November 05

Posted 30 September 2012 - 09:50 AM

View Postgunsmokingman, on 18 September 2012 - 10:31 AM, said:

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.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy