Solved

Using WSH to update REG_MULTI_SZ data type

Posted on 2000-03-15
4
1,537 Views
Last Modified: 2012-08-14
I need to add a registry value which has a data type of REG_MULTI_SZ.  I was hoping to do it with WSH (Windows Scripting Host) using VB but the documentation says that the RegWrite method cannot handle REG_MULTI_SZ data.

Is anyone aware of another means to accomplish this with WSH?
0
Comment
Question by:swartwe
  • 2
4 Comments
 
LVL 1

Expert Comment

by:ramshank
ID: 2637930
Try the following


RegRead Method
--------------
The following code segment will return the value of the registry key specified in
the strPath variable. The code below can also help in determining the data type
of the key being access. The following table shows the return value when using
the TypeName function on the registry key.

+---------------------------------------------------+
| Registry Key  | Return Data Type (using TypeName) |
+---------------------------------------------------+
| REG_SZ        | String                            |
+---------------------------------------------------+
| REG_EXPAND_SZ | String                            |
+---------------------------------------------------+
| REG_MULTI_SZ  | Variant Array                     |
+---------------------------------------------------+
| REG_DWORD     | Long                              |
+---------------------------------------------------+
| REG_BINARY    | Variant Array                     |
+---------------------------------------------------+

   Set WshShell = CreateObject("WScript.Shell")
   strPath = "HKCU\MyRegKey\Entry\Value1"
   varRegVal = WshShell.RegRead(strPath)
   WScript.Echo TypeName(varRegVal)
   'Check to see if the value is an array of values, then loop through them
   If VarType(varRegVal) And vbArray Then
       For i = LBound(varRegVal) To UBound(varRegVal)
           WScript.Echo varRegVal(i)
       Next
   Else
       WScript.Echo varRegVal
   End If
0
 

Author Comment

by:swartwe
ID: 2638392
While I appreciate the response and find it interesting, it does not answer my question ("I need to add a registry value which has a data type of REG_MULTI_SZ.").  Regrettably, I must reject this response.
0
 

Accepted Solution

by:
bxt earned 100 total points
ID: 2771399
I have run into the same problem.  I was hoping that somebody else would have answered this.  My only solution has been to create a program called RegMultiSz that convets a REG_SZ key to a REG_MULTI_SZ key.

I run it from script using a command line variable which is the key I want to change e.g.

REG_MULTI_SZ HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\abc

Here is the code, I can send you the .EXE if it is of use to you

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
      char hive[256];      
      char subkey[1024];
      char lastsubkey[1024];
      char key[256];
      char seps[]   = "\\";
      char *token;

    /* Establish string and get the first token: */
    token = strtok( lpCmdLine, seps );  
      strcpy(hive,token);
      strcpy(subkey,"");
      /* Get next token: */
      token = strtok( NULL, seps );
      while( token != NULL )  
      {
            strcat(subkey,token);            
            strcat(subkey,"\\");
            strcpy(key,token);
          /* Get next token: */
            token = strtok( NULL, seps );
            if (token!=NULL)
                  strcpy(lastsubkey,subkey);
            else
                  strcpy(subkey,lastsubkey);
      }      
      

      HKEY hKey;
      if (strcmp(hive,"HKEY_CLASSES_ROOT")==0)
            hKey=HKEY_CLASSES_ROOT;
      else if (strcmp(hive,"HKEY_CURRENT_CONFIG")==0)
            hKey=HKEY_CURRENT_CONFIG;
      else if (strcmp(hive,"HKEY_CURRENT_USER")==0)
                  hKey=HKEY_CURRENT_USER;
      else if (strcmp(hive,"HKEY_LOCAL_MACHINE")==0)
                  hKey=HKEY_LOCAL_MACHINE;
      else if (strcmp(hive,"HKEY_USERS")==0)
                  hKey=HKEY_USERS;      

      if (RegOpenKey(hKey,subkey,&hKey)==ERROR_SUCCESS)
      {
            BYTE sValue[80];
            DWORD nSize=80;

            if (RegQueryValueEx(hKey, key, NULL, NULL, sValue, &nSize)==ERROR_SUCCESS)
            {
                  sValue[nSize]=0;
                  RegSetValueEx(hKey, key, 0, REG_MULTI_SZ, (BYTE*)(LPCSTR)sValue, nSize+1);
            }
            RegCloseKey(hKey);  
      }

      return 0;
}
0
 

Author Comment

by:swartwe
ID: 2771460
While my preference was to add a REG_MULTI_SZ string using WSH, as of now, I don't think that it can be done with WSH.  Because of this conclusion, a couple of weeks ago I decided to write my own utility (I used the same API functions which you used in your utility).

I am giving you an excellent grade because you did provide a means by which to accomplish my needs (using the same approach that I ultimately chose).

I appreciate your help along with your offer to send me an exe (However, I won't be needing an exe).  

Thank you.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now