Benvenuto! Per postare e godere delle funzionalità del forum registrati, occorrono pochi secondi ed è gratis!

[aiuto]registro di sistema e vb.net
(Questo messaggio è stato modificato l'ultima volta il: 15/09/2011, 20:54 da Cato97.)

Coder
Messaggi: 633
Discussioni: 57
Registrato: 04-2011
Mix: 0
nel registro di sistema ho creato una cartella chiamata "cartella 1". in questa cartella vi è una sotto cartella: "cartella 2".

ciò che voglio chiedervi è come fare per eliminare "cartella 2" da vb.net

ringrazio in anticipo chi mi risponderà Happywide

EDIT: specifico che "cartella 1" e ovviamente anche "cartella 2" sono in "HKEY_LOCAL_MACHINE\SOFTWARE"

15/09/2011, 20:53
#1
Cerca
(Questo messaggio è stato modificato l'ultima volta il: 15/09/2011, 21:38 da Skyline@69.)

WarRock Hacks Coder
Messaggi: 940
Discussioni: 47
Registrato: 03-2011
Mix: 0
(15/09/2011, 20:53)Cato97 Ha scritto:

[Per vedere i link devi REGISTRARTI.]

nel registro di sistema ho creato una cartella chiamata "cartella 1". in questa cartella vi è una sotto cartella: "cartella 2".

ciò che voglio chiedervi è come fare per eliminare "cartella 2" da vb.net

ringrazio in anticipo chi mi risponderà Happywide

EDIT: specifico che "cartella 1" e ovviamente anche "cartella 2" sono in "HKEY_LOCAL_MACHINE\SOFTWARE"

Considerando che tu abbia qualcosa come:
    VB Programming
  1. Dim cartella1 As RegistryKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\cartella1")
  2. Dim cartella2 As RegistryKey = cartella1.CreateSubKey("cartella2")



semplicemente:
    VB Programming
  1. cartella1.DeleteSubKey("cartella2")



e se vuoi cancellare sia cartella 1 che cartella 2 e tutto il loro contenuto:
    VB Programming
  1. Registry.LocalMachine.DeleteSubKeyTree("cartella1")



15/09/2011, 21:36
#2
Cerca
(Questo messaggio è stato modificato l'ultima volta il: 15/09/2011, 21:53 da Cato97.)

Coder
Messaggi: 633
Discussioni: 57
Registrato: 04-2011
Mix: 0
grazie per avermi risposto sky, ti correggo una cosa: ti sei scordato di dire che all'inizio di tutto il codice va inserito:
    VBNET Programming
  1. Imports Microsoft.Win32


altrimenti "RegistryKey" dà errore

comunque ho usato questo codice:
    VBNET Programming
  1. Dim principale As RegistryKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\Dot Settings")
  2. Dim cart_prof As RegistryKey = principale.CreateSubKey(ListBox2.SelectedItem.ToString)
  3. principale.DeleteSubKey("cart_prof")


ma non funge; mi dà questo errore:

Impossibile eliminare la struttura ad albero di una sottochiave non esistente.

evidenziandomi:
    VBNET Programming
  1. principale.DeleteSubKey("cart_prof")



15/09/2011, 21:52
#3
Cerca
(Questo messaggio è stato modificato l'ultima volta il: 15/09/2011, 22:22 da Skyline@69.)

WarRock Hacks Coder
Messaggi: 940
Discussioni: 47
Registrato: 03-2011
Mix: 0
che ci fosse l'imports lo avevo dato per scontato...
sei sicuro che "ListBox2.SelectedItem.ToString" restituisca la stringa "cart_prof"?

fai cosi prima del punto in cui cancelli la chiava metti un break per il debug e vedi come stanno le cose Smile

EDIT:
Ho controllato ed è come immaginavo, il problema è che vb si fa troppi scrupoli per scrivere in LocalMachine, perchè richiede particolari privilegi, e pure avviando come amministratore non va..

infatti se vedi non ti da nessun errore ma in realtà sul registro la chiave non te la scrive...

puoi risolvere cambiando da localmachine a currentuser Smile
ho provato così e funge:
    VB Programming
  1. Dim principale As RegistryKey = Registry.CurrentUser.CreateSubKey("SOFTWARE\Dot Settings")
  2. Dim cart_prof As RegistryKey = principale.CreateSubKey("cart_prof")
  3. principale.DeleteSubKey("cart_prof")


Ovviamente nel createsubkey toglierai "cart_prof" e metterai il valore della listbox, ma assicurati che la listbox ritorni come valore "cart_prof"

15/09/2011, 22:14
#4
Cerca

Coder
Messaggi: 633
Discussioni: 57
Registrato: 04-2011
Mix: 0
si ok... ma la cartella che devo eliminare è in HKEY_LOCAL_MACHINE... comunque dà sempre lo stesso errore...

16/09/2011, 19:55
#5
Cerca
(Questo messaggio è stato modificato l'ultima volta il: 16/09/2011, 21:08 da Skyline@69.)

WarRock Hacks Coder
Messaggi: 940
Discussioni: 47
Registrato: 03-2011
Mix: 0
(16/09/2011, 19:55)Cato97 Ha scritto:

[Per vedere i link devi REGISTRARTI.]

si ok... ma la cartella che devo eliminare è in HKEY_LOCAL_MACHINE... comunque dà sempre lo stesso errore...

Il codice che ti ho postato per ultimo non può darti errore, perchè l'ho testato io.
Assicurati di avviare come amministratore e che il valore restituito dalla ListBox sia cart_prof..

se vuoi essere sicuro metti da parte listbox e scrivi direttamente cart_prof...insomma devi imparare il trucco di andare per gradi e capire come si comporta l'applicazione Smile

Per quando riguarda local machine te l'ho detto che è troppo complicato col vb, imposta il programma per lavorare al 100% in current user, ammesso che la cartella che vuoi eliminare la crei in anticipo sempre dal programma...

16/09/2011, 21:07
#6
Cerca

Coder
Messaggi: 633
Discussioni: 57
Registrato: 04-2011
Mix: 0
risolto così:

    VBNET Programming
  1. Dim principale As RegistryKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\Dot Settings\")
  2. principale.DeleteSubKey(ListBox2.SelectedItem)



16/09/2011, 23:00
#7
Cerca

WarRock Hacks Coder
Messaggi: 940
Discussioni: 47
Registrato: 03-2011
Mix: 0
(16/09/2011, 23:00)Cato97 Ha scritto:

[Per vedere i link devi REGISTRARTI.]

risolto così:

    VBNET Programming
  1. Dim principale As RegistryKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\Dot Settings\")
  2. principale.DeleteSubKey(ListBox2.SelectedItem)


a me in quel modo non va...che os usi?


17/09/2011, 13:34
#8
Cerca

Coder
Messaggi: 633
Discussioni: 57
Registrato: 04-2011
Mix: 0
xp sp3 32-bit... a me funge LOL

17/09/2011, 13:59
#9
Cerca

Il criceto mannaro
Messaggi: 3,536
Discussioni: 201
Registrato: 03-2011
Mix: 3,737
con xp è tutto piu facile, non è cosi cagac*** come vista o 7 Tounge


digger
17/09/2011, 14:21
#10
Cerca

Coder
Messaggi: 633
Discussioni: 57
Registrato: 04-2011
Mix: 0
appunto Asd anche se preferisco 7 a xp...

17/09/2011, 14:43
#11
Cerca
(Questo messaggio è stato modificato l'ultima volta il: 17/09/2011, 14:46 da Skyline@69.)

WarRock Hacks Coder
Messaggi: 940
Discussioni: 47
Registrato: 03-2011
Mix: 0
(17/09/2011, 14:43)Cato97 Ha scritto:

[Per vedere i link devi REGISTRARTI.]

appunto Asd anche se preferisco 7 a xp...

Allora sei strano Asd

Io comunque ho 7 e confermo che li non va, e non è difficile pensare che su xp vada e su 7 no Blush

EDIT:
Non so se quel pezzo di codice fa parte di un gioco o applicativo che vuoi rilasciare, ma viste le circostanza dovresti tenere conto che quindi quel programma non funzionerà su 7 Smile

17/09/2011, 14:44
#12
Cerca
(Questo messaggio è stato modificato l'ultima volta il: 17/09/2011, 20:15 da Cato97.)

Coder
Messaggi: 633
Discussioni: 57
Registrato: 04-2011
Mix: 0
lo terrò a mente Wink

EDIT:
mi serve un'altro aiutino... dovrei aggiungere le cartelle contenute in una cartella situata nel Registro di Sistema, in una ListBox... per farlo quando avevo le cartelle in un percorso sull'HDD usavo questo codice:

    VBNET Programming
  1. profili = My.Computer.FileSystem.GetDirectories(Application.StartupPath).ToArray
  2. For i = 0 To profili.Length - 1
  3. Dim lastSlash As Integer = profili(i).LastIndexOf("\") + 1
  4. profili(i) = profili(i).Substring(lastSlash)
  5. Next
  6. ListBox2.Items.AddRange(profili)



come posso fare?

17/09/2011, 19:55
#13
Cerca
(Questo messaggio è stato modificato l'ultima volta il: 17/09/2011, 20:38 da Skyline@69.)

WarRock Hacks Coder
Messaggi: 940
Discussioni: 47
Registrato: 03-2011
Mix: 0
questo è un esempio completo da cui ho tra l'altro estratto quella porzione che ti ho postato prima...
l'ho testato (su 7) e funge su tutti i sensi..
Provalo, studiatelo e implementalo come vuoi e come ti serve Smile

    VB Programming
  1. Imports System
  2. Imports Microsoft.Win32
  3.  
  4. Module Module1
  5. Sub Main()
  6. ' Create a subkey named Test9999 under HKEY_CURRENT_USER.
  7. Dim test9999 As RegistryKey = _
  8. Registry.CurrentUser.CreateSubKey("Test9999")
  9.  
  10. ' Create two subkeys under HKEY_CURRENT_USER\Test9999.
  11. test9999.CreateSubKey("TestName").Close()
  12. Dim testSettings As RegistryKey = _
  13. test9999.CreateSubKey("TestSettings")
  14.  
  15. ' Create data for the TestSettings subkey.
  16. testSettings.SetValue("Language", "French")
  17. testSettings.SetValue("Level", "Intermediate")
  18. testSettings.SetValue("ID", 123)
  19. testSettings.SetValue("Password", "Secret")
  20. testSettings.Close()
  21.  
  22. ' Print the information from the Test9999 subkey.
  23. Console.WriteLine("There are {0} subkeys under Test9999.", _
  24. test9999.SubKeyCount.ToString())
  25. For Each subKeyName As String In test9999.GetSubKeyNames()
  26. Dim tempKey As RegistryKey = _
  27. test9999.OpenSubKey(subKeyName)
  28. Console.WriteLine(vbCrLf & "There are {0} values for " & _
  29. "{1}.", tempKey.ValueCount.ToString(), tempKey.Name)
  30. For Each valueName As String In tempKey.GetValueNames()
  31. Console.WriteLine("{0,-8}: {1}", valueName, _
  32. tempKey.GetValue(valueName).ToString())
  33. Next
  34. Next
  35.  
  36. ' Delete the non-secure password value.
  37. testSettings = test9999.OpenSubKey("TestSettings", True)
  38. testSettings.DeleteValue("password")
  39.  
  40. ' Verify the deletion.
  41. Console.WriteLine(CType(testSettings.GetValue( _
  42. "password", "Password not found."), String))
  43. testSettings.Close()
  44.  
  45. ' Delete or close the new subkey.
  46. Console.Write(vbCrLf & "Delete newly created " & _
  47. "registry key? (Y/N) ")
  48. If Char.ToUpper(Convert.ToChar(Console.Read())) = "Y"c Then
  49. Registry.CurrentUser.DeleteSubKeyTree("Test9999")
  50. Console.WriteLine(vbCrLf & "Registry key {0} deleted.", _
  51. test9999.Name)
  52. Else
  53. Console.WriteLine(vbCrLf & "Registry key {0} closed.", _
  54. test9999.ToString())
  55. test9999.Close()
  56. End If
  57.  
  58. End Sub
  59.  
  60. End Module



[Per vedere i link devi REGISTRARTI.]


Fonte:

[Per vedere i link devi REGISTRARTI.]



17/09/2011, 20:36
#14
Cerca
(Questo messaggio è stato modificato l'ultima volta il: 17/09/2011, 22:22 da Cato97.)

Coder
Messaggi: 633
Discussioni: 57
Registrato: 04-2011
Mix: 0
l'avevo visto anch'io questo esempio ma... sbaglio o non c'è ciò che cerco? Disgusted

17/09/2011, 22:22
#15
Cerca


Discussioni simili
Discussione Autore Risposte Letto Ultimo messaggio
  [Guida] Cambiare lingua ad un gioco che utilizza una lingua di sistema Cato97 10 59,628 25/08/2017, 16:46
Ultimo messaggio: Romolo
  [aiuto] No segnale su sapphire R9 280. Pocciox 5 2,391 14/01/2015, 22:11
Ultimo messaggio: digger
  aiuto portatile oirad94 1 1,666 22/12/2014, 16:27
Ultimo messaggio: Admin



Utenti che stanno guardando questa discussione: 1 Ospite(i)