For loop in Visual basic

Home Forums Scripting Windows Script Host For loop in Visual basic

This topic contains 3 replies, has 3 voices, and was last updated by JeremyW JeremyW 9 years, 3 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • Avatar
    XtaZee
    Member
    #149037

    I need the following to be in VBScript

    if you can help

    FOR /F “tokens=2* delims= ” %%A IN (‘REG QUERY “HKCUSoftwareMicrosoftWindowsCurrentVersionExplorerShell Folders” /v desktop’) DO SET DeskTop=%%B

    Echo DeskTop=%DeskTop%
    [/Code]

    Thanks![Code]
    FOR /F “tokens=2* delims= ” %%A IN (‘REG QUERY “HKCUSoftwareMicrosoftWindowsCurrentVersionExplorerShell Folders” /v desktop’) DO SET DeskTop=%%B

    Echo DeskTop=%DeskTop%
    [/Code]

    Thanks!

    JeremyW
    JeremyW
    Moderator
    #269961

    Re: For loop in Visual basic

    Here’s the code to get the desktop location using VBS.

    const HKEY_CURRENT_USER = &H80000001
    strComputer = “.”
    Set oReg=GetObject( _
    “winmgmts:{impersonationLevel=impersonate}!\” &_
    strComputer & “rootdefault:StdRegProv”)
    strKeyPath = “SoftwareMicrosoftWindowsCurrentVersionExplorerShell Folders”
    strValueName = “Desktop”
    oReg.GetStringValue _
    HKEY_CURRENT_USER,strKeyPath,strValueName,strDesktop
    WScript.Echo strDesktop[/CODE]

    [B]”strDesktop”[/B] is the variable that contains the location. You can take out the [B]Wscript.Echo[/B] line and replace it with whatever you’re wanting the desktop location for.[CODE]const HKEY_CURRENT_USER = &H80000001
    strComputer = “.”
    Set oReg=GetObject( _
    “winmgmts:{impersonationLevel=impersonate}!\” &_
    strComputer & “rootdefault:StdRegProv”)
    strKeyPath = “SoftwareMicrosoftWindowsCurrentVersionExplorerShell Folders”
    strValueName = “Desktop”
    oReg.GetStringValue _
    HKEY_CURRENT_USER,strKeyPath,strValueName,strDesktop
    WScript.Echo strDesktop[/CODE]

    “strDesktop” is the variable that contains the location. You can take out the Wscript.Echo line and replace it with whatever you’re wanting the desktop location for.

    Rems
    Rems
    Moderator
    #227714

    Re: For loop in Visual basic

    Different solutions,

    1)
    Const DESKTOP = &H10

    ‘ [url]http://www.cruto.com/resources/vbscript/vbscript-examples/desktop/special/[/url]

    Set objShell = CreateObject(“Shell.Application”)
    Set objFolder = objShell.Namespace(DESKTOP)
    Set objFolderItem = objFolder.Self
    strDeskTop = objFolderItem.Path

    wscript.echo strDeskTop[/CODE]

    OR,

    2)
    [CODE]Set WshShell = createobject(“Wscript.Shell”)
    strDeskTop = WshShell.SpecialFolders(“Desktop”)

    wscript.echo strDeskTop[/CODE][CODE]Const DESKTOP = &H10

    http://www.cruto.com/resources/vbscript/vbscript-examples/desktop/special/

    Set objShell = CreateObject(“Shell.Application”)
    Set objFolder = objShell.Namespace(DESKTOP)
    Set objFolderItem = objFolder.Self
    strDeskTop = objFolderItem.Path

    wscript.echo strDeskTop[/CODE]

    OR,

    2)
    Set WshShell = createobject(“Wscript.Shell”)
    strDeskTop = WshShell.SpecialFolders(“Desktop”)

    wscript.echo strDeskTop[/CODE][CODE]Set WshShell = createobject(“Wscript.Shell”)
    strDeskTop = WshShell.SpecialFolders(“Desktop”)

    wscript.echo strDeskTop[/CODE]

    Avatar
    XtaZee
    Member
    #224357

    Re: For loop in Visual basic

    Thanks!!!!

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

Register for this Petri Webinar!

Software-Defined Unlimited Backup Storage

Tuesday, August 27, 2019 @ 1:00 pm EDT

A Scale-Out Backup storage infrastructure is a must-have technology for your backups. In this webinar, join expert Rick Vanover for a look on what real-world problems are solved by the Scale-Out Backup Repository.

Register Now

Sponsored By