Registery edit

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
26 posts Page 1 of 3
Contributors
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

Registery edit
AnoPem
I use a reg file to create an explorer contextmenu item

When you right click and click MyItem which can only be shown if you right click a folder it opens my program, but how can i do so it add the folders destination and name to 2 diffrent textboxes in my program?

And how can i add this regestry key with vb.net?

Code: Select all
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\MyItem]

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\MyItem\command]
@="\"C:\\Users\\AnoPem\\Documents\\Visual Studio 2010\\Projects\\AP Lock\\AP Lock\\bin\\Debug\\MyProgram.exe\""

https://t.me/pump_upp
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

Re: Registery edit
M1z23R
On form load use MsgBox(Command().tostring)
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: Registery edit
MrAksel
Code: Select all
        Dim k As RegistryKey = Registry.LocalMachine.CreateSubKey("\SOFTWARE\Classes\Folder\shell\MyItem\command")
        'k.SetValue("", "C:\Users\AnoPem\Documents\Visual Studio 2010\Projects\AP Lock\AP Lock\bin\Debug\MyProgram.exe")'
        k.SetValue("", System.IO.Directory.GetCurrentDirectory() + "\MyProgram.exe %1")
In your load event, you can have this:
Code: Select all
TextBox1.Text = System.Environment.GetCommandLineArgs()(0)
TextBox2.Text = System.IO.Directory.GetParent(TextBox1.Text).FullPath
I think that would work. Didn't test it though.
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

Re: Registery edit
AnoPem
M1z23R wrote:
On form load use MsgBox(Command().tostring)
This does not work :(
https://t.me/pump_upp
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: Registery edit
MrAksel
Well, did my work?
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

Re: Registery edit
AnoPem
MrAksel wrote:
Code: Select all
        Dim k As RegistryKey = Registry.LocalMachine.CreateSubKey("\SOFTWARE\Classes\Folder\shell\MyItem\command")
        'k.SetValue("", "C:\Users\AnoPem\Documents\Visual Studio 2010\Projects\AP Lock\AP Lock\bin\Debug\MyProgram.exe")'
        k.SetValue("", System.IO.Directory.GetCurrentDirectory() + "\MyProgram.exe %1")
In your load event, you can have this:
Code: Select all
TextBox1.Text = System.Environment.GetCommandLineArgs()(0)
TextBox2.Text = System.IO.Directory.GetParent(TextBox1.Text).FullPath
I think that would work. Didn't test it though.
The registry add dosent work and i get this error on the form load

Code: Select all
Error	1	'System.IO.FileSystemInfo.FullPath' is not accessible in this context because it is 'Protected'
and the first line of the form load code only shows my programs path, i want the folder i right clicks path
https://t.me/pump_upp
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: Registery edit
MrAksel
Okay, replace the load code with this:
Code: Select all
TextBox1.Text = System.Environment.GetCommandLineArgs()(1)
TextBox2.Text = TextBox1.Text.Substring(TextBox1.Text.LastIndexOf("\"c) + 1)
TextBox1.Text = TextBox1.Text.Remove(TextBox1.Text.LastIndexOf("\"c))
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

Re: Registery edit
AnoPem
MrAksel wrote:
Okay, replace the load code with this:
Code: Select all
TextBox1.Text = System.Environment.GetCommandLineArgs()(1)
TextBox2.Text = TextBox1.Text.Substring(TextBox1.Text.LastIndexOf("\"c) + 1)
TextBox1.Text = TextBox1.Text.Remove(TextBox1.Text.LastIndexOf("\"c))
This does not work, i get this error

http://pastebin.com/HrGqAPED
https://t.me/pump_upp
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

Re: Registery edit
AnoPem
Ive found a way to get the registry edited now i just need to know how i can load the path from the folder i right click into the program i open in the contextmenu
https://t.me/pump_upp
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: Registery edit
MrAksel
Blast your way lol. Fully working example for me.
Add to registry:
Code: Select all
        Dim k As RegistryKey = Registry.LocalMachine.CreateSubKey("\SOFTWARE\Classes\Folder\shell\MyItem\command")
        k.SetValue("", System.IO.Directory.GetCurrentDirectory() + "\MyProgram.exe /
folder:%1")
        k.Close()
Load to textboxes:
Code: Select all
Dim argument As String = ""
For Each arg As String In System.Environment.GetCommandLineArgs()
   If arg.StartsWith("/folder:") Then 
      argument = arg.Substring(8)
      Exit For
   End If
Next
If argument <> "" AndAlso System.IO.Directory.Exists(argument) Then
   Dim f As New DirectoryInfo(argument)
   TextBox1.Text = f.Parent.FullName
   TextBox2.Text = f.Name
Else
   MessageBox.Show("Could not find folder.")
End If
Last edited by MrAksel on Tue May 15, 2012 7:40 pm, edited 1 time in total.
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
26 posts Page 1 of 3
Return to “Coding Help & Support”