Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 467
  • Last Modified:

Trying to add a Registry key without User intervention

We are trying to add this with VB without user intervention.  Would greatly appreciate a simple script to accomplish this that we can place on our server and run.  Thanks ahead of time.  Scripting is not my bag and appreciate any help in this matter.

To Add file types to Level1Remove key:

Run Regedit, and go to this key:

HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Outlook\Security (change 10.0 to 9.0 for Outlook 2000 SP3 or to 11.0 for Outlook 2003)
Under that key, add a new string value named Level1Remove.
For the value for Level1Remove, enter a semicolon-delimited list of file extensions. For example, entering this:

.zip;.mdb;.url

would force you to save Zip file type and unblock Microsoft Access files and Internet shortcuts.
0
Shenook
Asked:
Shenook
  • 10
  • 10
  • 2
  • +1
1 Solution
 
andrewbleakleyCommented:
Are you wanting to add these values to a remote machine ?
0
 
ShenookAuthor Commented:
I actually need to do both.  I need a local on future systems we are deploying to run this script and already deployed systems need to get done remotely if possible.

Increased points since I didn't think of that in the question.
0
 
nffvrxqgrcfqvvcCommented:
Option Explicit


Type SECURITY_ATTRIBUTES
    nLength As Long
    lpSecurityDescriptor As Long
    bInheritHandle As Long
End Type

'API Declarations
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, ByRef lpType As Long, ByVal lpData As String, ByRef lpcbData As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long

'Types Enum Definition
Public Enum T_KeyClasses
    HKEY_CLASSES_ROOT = &H80000000
    HKEY_CURRENT_CONFIG = &H80000005
    HKEY_CURRENT_USER = &H80000001
    HKEY_LOCAL_MACHINE = &H80000002
    HKEY_USERS = &H80000003
End Enum

'Constants Definition
Private Const SYNCHRONIZE = &H100000
Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_CREATE_LINK = &H20
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_EVENT = &H1
Private Const KEY_NOTIFY = &H10
Private Const READ_CONTROL = &H20000
Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)
Private Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
Private Const KEY_EXECUTE = (KEY_READ)
Private Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
Private Const REG_BINARY = 3
Private Const REG_CREATED_NEW_KEY = &H1
Private Const REG_DWORD = 4
Private Const REG_DWORD_BIG_ENDIAN = 5
Private Const REG_DWORD_LITTLE_ENDIAN = 4
Private Const REG_EXPAND_SZ = 2
Private Const REG_FULL_RESOURCE_DESCRIPTOR = 9
Private Const REG_LINK = 6
Private Const REG_MULTI_SZ = 7
Private Const REG_NONE = 0
Private Const REG_SZ = 1
Private Const REG_NOTIFY_CHANGE_ATTRIBUTES = &H2
Private Const REG_NOTIFY_CHANGE_LAST_SET = &H4
Private Const REG_NOTIFY_CHANGE_NAME = &H1
Private Const REG_NOTIFY_CHANGE_SECURITY = &H8
Private Const REG_OPTION_BACKUP_RESTORE = 4
Private Const REG_OPTION_CREATE_LINK = 2
Private Const REG_OPTION_NON_VOLATILE = 0
Private Const REG_OPTION_RESERVED = 0
Private Const REG_OPTION_VOLATILE = 1
Private Const REG_LEGAL_CHANGE_FILTER = (REG_NOTIFY_CHANGE_NAME Or REG_NOTIFY_CHANGE_ATTRIBUTES Or REG_NOTIFY_CHANGE_LAST_SET Or REG_NOTIFY_CHANGE_SECURITY)
Private Const REG_LEGAL_OPTION = (REG_OPTION_RESERVED Or REG_OPTION_NON_VOLATILE Or REG_OPTION_VOLATILE Or REG_OPTION_CREATE_LINK Or REG_OPTION_BACKUP_RESTORE)
'Delete e Registry Key with all his contained Values
Public Sub DeleteRegistryKey(rClass As T_KeyClasses, Path As String)
    Dim res As Long

    res = RegDeleteKey(rClass, Path)
End Sub

'Delete a Value from the Registry
Public Sub DeleteValue(rClass As T_KeyClasses, Path As String, sKey As String)
    Dim hKey As Long
    Dim res As Long

    res = RegOpenKeyEx(rClass, Path, 0, KEY_ALL_ACCESS, hKey)
    res = RegDeleteValue(hKey, sKey)
    RegCloseKey hKey
End Sub

'Creates a New Registry Key
Public Sub CreateRegistryKey(rClass As T_KeyClasses, Path As String)
    Dim hKey As Long
    Dim res As Long
    Dim Y As SECURITY_ATTRIBUTES
    Dim Operation As Long

    res = RegCreateKeyEx(rClass, Path, 0, "", 0, KEY_ALL_ACCESS, Y, hKey, Operation)
    RegCloseKey hKey
End Sub

'Get a specific Registry Value (to access the Default Registry Key Value set sKey parameter as "")
Public Function GetRegValue(KeyRoot As T_KeyClasses, Path As String, sKey As String) As String
    Dim hKey As Long
    Dim KeyValType As Long
    Dim KeyValSize As Long
    Dim KeyVal As String
    Dim tmpVal As String
    Dim res As Long
    Dim i As Integer

    res = RegOpenKeyEx(KeyRoot, Path, 0, KEY_ALL_ACCESS, hKey)
    If res <> 0 Then GoTo Errore
    tmpVal = String(1024, 0)
    KeyValSize = 1024
    res = RegQueryValueEx(hKey, sKey, 0, KeyValType, tmpVal, KeyValSize)
    If res <> 0 Then GoTo Errore
    If (Asc(Mid(tmpVal, KeyValSize, 1)) = 0) Then
        tmpVal = Left(tmpVal, KeyValSize - 1)
    Else
        tmpVal = Left(tmpVal, KeyValSize)
    End If
    Select Case KeyValType
    Case REG_SZ
        KeyVal = tmpVal
    Case REG_DWORD
        For i = Len(tmpVal) To 1 Step -1
            KeyVal = KeyVal + Hex(Asc(Mid(tmpVal, i, 1)))
        Next
        KeyVal = Format("&h" + KeyVal)
    End Select
    GetRegValue = KeyVal
    RegCloseKey hKey
    Exit Function
Errore:
    GetRegValue = ""
    RegCloseKey hKey
End Function

'Create or Modify a Registry Value (to access the Default Registry Key Value set sKey parameter as "")
Public Function SetRegValue(KeyRoot As T_KeyClasses, Path As String, sKey As String, NewValue As String) As Boolean
    Dim hKey As Long
    Dim KeyValType As Long
    Dim KeyValSize As Long
    Dim KeyVal As String
    Dim tmpVal As String
    Dim res As Long
    Dim i As Integer
    Dim X As Long

    res = RegOpenKeyEx(KeyRoot, Path, 0, KEY_ALL_ACCESS, hKey)
    If res <> 0 Then GoTo Errore
    tmpVal = String(1024, 0)
    KeyValSize = 1024
    res = RegQueryValueEx(hKey, sKey, 0, KeyValType, tmpVal, KeyValSize)
    Select Case res
    Case 2
        KeyValType = REG_SZ
    Case Is <> 0
        GoTo Errore
    End Select
    Select Case KeyValType
    Case REG_SZ
        tmpVal = NewValue
    Case REG_DWORD
        X = Val(NewValue)
        tmpVal = ""
        For i = 0 To 3
            tmpVal = tmpVal & Chr(X Mod 256)
            X = X \ 256
        Next
    End Select
    KeyValSize = Len(tmpVal)
    res = RegSetValueEx(hKey, sKey, 0, KeyValType, tmpVal, KeyValSize)
    If res <> 0 Then GoTo Errore
    SetRegValue = True
    RegCloseKey hKey
    Exit Function
Errore:
    SetRegValue = False
    RegCloseKey hKey
End Function

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
ShenookAuthor Commented:
egl1044 That was greek to me.  I didn't see the key in that whole thing you posted.  I'm not script literate so I'm not sure what I have to modify in your above statement.
0
 
nffvrxqgrcfqvvcCommented:
You are using visual basic right????
0
 
nffvrxqgrcfqvvcCommented:
Instead of all that here is a stripped down version.
'Add this to the Form_Declerations

Option Explicit
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
    Private Const HKEY_CURRENT_USER = &H80000001
    Private Const HKEY_LOCAL_MACHINE = &H80000002
    Private Const ERROR_SUCCESS = 0&
    Private Const REG_SZ = 1
    Private Const REG_DWORD = 4

Private Sub SaveString(Hkey As Long, strPath As String, strValue As String, strData As String)
    Dim keyhand As Long
    Dim x As Long
    Dim r As Long
    x = RegCreateKey(Hkey, strPath, keyhand)
    x = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strData, Len(strData))
    x = RegCloseKey(keyhand)
End Sub


'Creat a command button
'Add the following code inside the command button


Call SaveString(HKEY_CURRENT_USER, "Software\Microsoft\Office\10.\Outlook\Security", "Level1Remove", ".zip;.mdb;.url")

0
 
vinnyd79Commented:
If you are looking to do this from a script you need to use the RegWrite Method:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsmthregwrite.asp
0
 
vinnyd79Commented:
Maybe something like this:

Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\Software\Microsoft\Office\10.0\Outlook\Security\Level1Remove", ".zip;.mdb;.url", "REG_SZ"

Set WshShell = Nothing
0
 
ShenookAuthor Commented:
I am used to using just notepad and then saving as a vbs.  
0
 
nffvrxqgrcfqvvcCommented:
Then vinnyd79's comment is what you are looking for
0
 
ShenookAuthor Commented:
I've tried to create a reg write method but it still prompts the user whether or not they want to modify the registry key.  I just don't want the user prompted.  Just want to have it run without their intervention.
0
 
ShenookAuthor Commented:
Increased points because of effort
0
 
nffvrxqgrcfqvvcCommented:
'I dont know how else you would accomplish this, if you have visual basics you could easily do this without interaction.

'If you want I could compile the code in VB and send you the .exe.
'However as long as it's not against EE rules.

Also I don't know if that script prompts everyone, pherhaps you have limitations on your account. Otherwise just ask me for a compiled version and I will send it.
0
 
nffvrxqgrcfqvvcCommented:
What I could do is have the .exe read from a text file that way you can change the registry strings as needed.

example:

doreg.exe <---is the compiled version which holds the writing to the registry
regcontents.txt <---which would hold your settings such as Software\Microsoft\Office\10.0\Outlook\Security

but you can change the text file at anytime pointing to somewere else in the registry all you would need to do is change regcontents.txt.

0
 
ShenookAuthor Commented:
That would be great.  If you sent it my way I'll try to run it on my test system and see if I get the prompt.  I'll increase the points and assign right after if it works.
0
 
ShenookAuthor Commented:
I think it will be software\microsoft\office\11.0\outlook\security instead of 10.0 since we are office 2003
0
 
nffvrxqgrcfqvvcCommented:
okay well I will make it so you can just edit the text file to the location in the registry
0
 
nffvrxqgrcfqvvcCommented:
Okay finished..

The files are located here::  http://members.lycos.co.uk/optonline/vbhelp/doreg/
Download the .zip file which contains both doreg.exe and regcontents.ini

regcontents.ini holds all your information so you can have a look inside of it, you will understand it as soon as you see it.

Theres 2 things you must know for this to work.
Both doreg.exe and regcontents.ini have to be in the same folder.

Also you will notice that in the regcontents.ini file the HKEY looks like this: &H80000001
That simply means your writing to HKEY_CURRENT_USER
If you want to change it to something else then below is the value's you need to change to write to that portion of the registry
ie. if you want to write to HKEY_LOCAL_MACHINE then just change &H80000001 <----that to this &H80000002

HKEY_CURRENT_USER = &H80000001
HKEY_LOCAL_MACHINE = &H80000002
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_CONFIG = &H80000005
HKEY_USERS = &H80000003

You will understand better once you see it.

Good Luck
Regards,
EGL
0
 
ShenookAuthor Commented:
Thanks so much. I see what is going on there.
0
 
ShenookAuthor Commented:
I'll post again tomorrow.
0
 
nffvrxqgrcfqvvcCommented:
I see that you accepted the answere, May I ask what your going to post tomorrow?

Did this not solve your problem?
0
 
ShenookAuthor Commented:
I just tried it at work and it works great.  Just wanted to post a follow up to let you know it worked on more than just my home system.  That's all.  Thanks again.
0
 
nffvrxqgrcfqvvcCommented:
Since this was programmed in VB, you will need the Visual basic runtime files..incase a computer doesn't have them installed. you will need to install them on there computer.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 10
  • 10
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now