Программно добавить «My Network Place» для FTP-сайта? - PullRequest
1 голос
/ 20 августа 2009

Можно ли в любом случае создать небольшой исполняемый или командный файл для установки нового «Моего сетевого места» в Windows? Это для FTP-сайта, если это имеет значение.

XP будет в первую очередь целевой машиной, но если я смогу найти что-то, что будет работать на Vista, это тоже здорово.

Ответы [ 2 ]

0 голосов
/ 28 марта 2013

Да, есть. Папкой NetHood можно управлять с помощью vbScript. Обратитесь к этой теме форума для получения дополнительной информации. На XP Pro у меня работает следующее:

Option Explicit
On Error Goto 0

'ShellSpecialFolderConstants
Const ssfNETHOOD = 19 '(&H13) Special Folder NETHOOD

Dim objWSHShell, objShell, objFolder, objFolderItem, strNetHood
Dim strShortcutName, strShortcutPath, objShortcut

Set objWSHShell = CreateObject("Wscript.Shell")
Set objShell = CreateObject("Shell.Application")

Set objFolder = objShell.Namespace(ssfNETHOOD)
Set objFolderItem = objFolder.Self
strNetHood = objFolderItem.Path

strShortcutName = "FTP to localhost"
strShortcutPath = "ftp://username@localhost/"

Set objShortcut = objWSHShell.CreateShortcut(strNetHood & "\" & strShortcutName & ".lnk")
objShortcut.TargetPath = strShortcutPath
objShortcut.Save
0 голосов
/ 20 августа 2009

Я написал этот скрипт для подключения к FTP через прокси-сервер. Вы можете адаптировать его для своих нужд. Он запрашивает имя файла и папку, к которой вы пытаетесь получить доступ. Просто вырежьте код, который вам не нужен, и вам будет хорошо.

Вам также потребуется изменить переменную FTP-сервера. Счастливое кодирование:

Option Explicit

Dim objShell, strFTPScriptFileName, strFile2Get
Dim strLocalFolderName, strFTPServerName, strLoginID
Dim strPassword, strFTPServerFolder, strFileToGet, returnCode


'Customize code here to fit your needs
strFTPServerName = "proxy.prv"
strLocalFolderName = ""
strLoginID = ""
strPassword = ""
strFTPServerFolder = ""
strFileToGet = ""




strLocalFolderName = GetLocalFolder()
strLoginID = InputBox("Enter FTP Username: ", "Enter FTP Username", "Authentication_Method@Destination_FTP_Host")
strPassword = InputBox("Enter FTP Password: ", "Enter FTP Password", "Authentication_Method@Destination_FTP_Host")
strFTPServerFolder = InputBox("Enter FTP folder that you want to access: ", "Enter FTP Folder", "/")
strFileToGet = InputBox("Enter the filename located on the FTP that you want to retrieve: ", "Enter FTP file", "*.*")

if strLoginID = "" then 
    WScript.Echo "You must specify a Login ID for this script to work"
    WScript.Quit()
end if

if strPassword = "" then 
    WScript.Echo "You must specify a Password for this script to work"
    WScript.Quit()
end if

if strFTPServerFolder = "" then 
    WScript.Echo "You must specify a FTP Folder to access for this script to work"
    WScript.Quit()
end if

if strFileToGet = "" then 
    WScript.Echo "You must specify a Filename to download for this script to work"
    WScript.Quit()
end if



Call WriteFTPScript()



Set objShell = WScript.CreateObject( "WScript.Shell" )
returnCode = objShell.Run( "cmd.exe /c ftp -s:" & chr(34) & strFTPScriptFileName & chr(34), 1, true)

if (returnCode = 0) then
   Wscript.echo("Your file has been downloaded.")
else
   Wscript.echo("An error has occured while attempting to download your file.")
End if

objShell.Run (strLocalFolderName)
Set objShell = Nothing



' **************************************************************************
' Creates the FTP script text file
Function WriteFTPScript()

    Dim objFSO, objMyFile
    strFTPScriptFileName = strLocalFolderName & "\FTPScript.txt"        'File to be created to hold ftp script data

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    If (objFSO.FileExists(strFTPScriptFileName)) Then
            objFSO.DeleteFile (strFTPScriptFileName)
    End If

    Set objMyFile = objFSO.CreateTextFile(strFTPScriptFileName, True)

    objMyFile.WriteLine ("open " & strFTPServerName)
    objMyFile.WriteLine (strLoginID)
    objMyFile.WriteLine (strPassword)
    objMyFile.WriteLine ("cd " & strFTPServerFolder)
    objMyFile.WriteLine ("lcd " & strLocalFolderName)
    objMyFile.WriteLine ("get " & strFileToGet)
    objMyFile.WriteLine ("bye")


    objMyFile.Close
    Set objFSO = Nothing
    Set objMyFile = Nothing

End Function



' **************************************************************************
' Dialog box to select folder to download to
Function GetLocalFolder()

    Const BIF_returnonlyfsdirs = &H0001
    Const BIF_editbox = &H0010
    Dim wsh, objDlg, objF

    Set objDlg = WScript.CreateObject("Shell.Application")
    Set objF = objDlg.BrowseForFolder (&H0, "Select the destination folder to download FTP files to:", BIF_editbox + BIF_returnonlyfsdirs)

    If IsValue(objF) Then 
        GetLocalFolder = objF.ParentFolder.ParseName(objF.Title).Path
    Else
        WScript.Echo "You MUST specify a folder to download files to.  Application will now exit."
        WScript.Quit
    End If

end function


' **************************************************************************
' Verifies if the the object contains a value
Function IsValue(obj)
    Dim tmp
    On Error Resume Next
    tmp = " " & obj
    If Err <> 0 Then
        IsValue = False
    Else
        IsValue = True
    End If
    On Error GoTo 0
End Function



' **************************************************************************
' Verifies if the the object is a folder
Function IsFolder(obj)
    Dim objFSO
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    if objFSO.IsFolder(obj) then 
        IsFolder = True 
    end if



End Function
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...