Vb.net HTA-对象需要Windows 8.1
我创建了一个小型HTA来帮助新机器成像。HTA将用户数据从其用户文件夹、firefox和chrome配置文件复制到新机器上。该脚本通过UNC连接到远程计算机,检查给定的用户名和特定文件夹,如果存在这些文件夹,它会将文件复制到新计算机 如果我运行脚本并将目标文件夹设置为“c:\temp”之类的通用文件夹,它工作正常,没有错误。但是,当我将目标文件夹设置为脚本中所示的正确路径时,会出现以下错误。我看不出有什么问题。有人能帮忙吗Vb.net HTA-对象需要Windows 8.1,vb.net,windows,vbscript,hta,Vb.net,Windows,Vbscript,Hta,我创建了一个小型HTA来帮助新机器成像。HTA将用户数据从其用户文件夹、firefox和chrome配置文件复制到新机器上。该脚本通过UNC连接到远程计算机,检查给定的用户名和特定文件夹,如果存在这些文件夹,它会将文件复制到新计算机 如果我运行脚本并将目标文件夹设置为“c:\temp”之类的通用文件夹,它工作正常,没有错误。但是,当我将目标文件夹设置为脚本中所示的正确路径时,会出现以下错误。我看不出有什么问题。有人能帮忙吗 电话:249 字符:38 错误:需要对象:“dFolder” 代码:0
电话:249 字符:38 错误:需要对象:“dFolder” 代码:0 URL: file:///CopyData.hta
复制用户数据
在我看到的第107行,您的destFolder
变量应该以“.contacts”开头吗destFolder=“c:\users\”&strUserName&“\.contacts”
1)outlook案例没有定义目标文件夹2)我认为在尝试将任何内容复制到ITOLL之前,您应该检查目标文件夹是否存在。我真的希望是这样。我不敢相信我忽略了这一点。啊!谢谢各位。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<!--
'#==============================================================================
'#==============================================================================
'# SCRIPT.........: CopyData.hta
'# AUTHOR.........: brandon h.
'# VERSION........:
'# DATE...........:
'# LICENSE........:
'# COMMENT........: Copy user data from remote device to local device.
'# Run script on destination device.
'#==============================================================================
'#==============================================================================
-->
<html>
<hta:application
applicationname="CopyData"
border="thin"
borderstyle="normal"
innerborder="no"
caption="yes"
contextmenu="no"
icon=""
maximizebutton="no"
minimizebutton="no"
navigable="no"
scroll="no"
scrollflat="no"
selection="no"
showintaskbar="yes"
singleinstance="yes"
sysmenu="yes"
windowstate="normal"
>
<head>
<title>Copy User Data</title>
<script type="text/javascript">
<!--
function loadHTA() {
// window size
var resW=screen.availWidth
var resH=screen.availHeight
if (resW >= 800) {
myW=resW/4
myH=resH/4
self.focus()
self.moveTo(eval(resW/2-myW/2), eval(resH/2-myH/2))
self.resizeTo(300, 250)
} else {
self.focus()
}
}
</script>
<script language="vbscript">
Option Explicit
' Define global variables
Const FOF_CREATEPROGRESSDLG = &H10&
Dim userName, wShell, oFSO, oShell, strIP
Dim strComputer, strUserName, objWMIService
Dim sourceFolder, destFolder, dest, dFolder
' Create global objects
Set wShell = CreateObject("WScript.Shell")
Set oShell = CreateObject("Shell.Application")
Set oFSO = CreateObject("Scripting.FileSystemObject")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'**** Used javascript instead - see loadHTA function ****
' Set window location and size
'Sub Window_onLoad
' window.resizeTo 200,200
' window.moveTo (screen.width - 600)/2, (screen.height - 200)/2
'End Sub
' Check if folders exist on remote device
Function CopyData()
' Create function related objects
Set wShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
' Define function related variables
strUserName = document.all.item("userName").value
strIP = document.all.item("ip").value
' Check for root user folder
If NOT oFSO.FolderExists("\\" & strIP & "\c$\users\" & strUserName) Then
wShell.popup "User: " & strUserName & " does not exist.",,"Error", 48
'window.close()
Else
' Contacts
If oFSO.FolderExists("\\" & strIP & "\c$\users\" & strUserName & "\contacts") Then
'wShell.popup "contacts",,"Error", 48
'destFolder = "\\booger\home\bhoneycutt\tmp"
sourceFolder = "\\" & strIP & "\c$\users\" & strUserName & "\contacts"
destFolder = "c:\users\" & strUserName & "\.contacts"
CopyRemote sourceFolder, destFolder
End If
' Desktop
If oFSO.FolderExists("\\" & strIP & "\c$\users\" & strUserName & "\desktop") Then
'wShell.popup "desktop",,"Error", 48
'destFolder = "\\booger\home\bhoneycutt\tmp"
sourceFolder = "\\" & strIP & "\c$\users\" & strUserName & "\desktop"
destFolder = "c:\users\" & strUserName & "\desktop"
CopyRemote sourceFolder, destFolder
End If
' Downloads
If oFSO.FolderExists("\\" & strIP & "\c$\users\" & strUserName & "\downloads") Then
'wShell.popup "downloads",,"Error", 48
'destFolder = "\\booger\home\bhoneycutt\tmp"
sourceFolder = "\\" & strIP & "\c$\users\" & strUserName & "\downloads"
destFolder = "c:\users\" & strUserName & "\downloads"
CopyRemote sourceFolder, destFolder
End If
' Favorites
If oFSO.FolderExists("\\" & strIP & "\c$\users\" & strUserName & "\favorites") Then
'wShell.popup "favorites",,"Error", 48
'destFolder = "\\booger\home\bhoneycutt\tmp"
sourceFolder = "\\" & strIP & "\c$\users\" & strUserName & "\favorites"
destFolder = "c:\users\" & strUserName & "\favorites"
CopyRemote sourceFolder, destFolder
End If
' Links
If oFSO.FolderExists("\\" & strIP & "\c$\users\" & strUserName & "\links") Then
'wShell.popup "links",,"Error", 48
'destFolder = "\\booger\home\bhoneycutt\tmp"
sourceFolder = "\\" & strIP & "\c$\users\" & strUserName & "\links"
destFolder = "c:\users\" & strUserName & "\links"
CopyRemote sourceFolder, destFolder
End If
' Documents
If oFSO.FolderExists("\\" & strIP & "\c$\users\" & strUserName & "\documents") Then
'wShell.popup "documents",,"Error", 48
'destFolder = "\\booger\home\bhoneycutt\tmp"
sourceFolder = "\\" & strIP & "\c$\users\" & strUserName & "\documents"
destFolder = "c:\users\" & strUserName & "\documents"
CopyRemote sourceFolder, destFolder
End If
' NoMachine
If oFSO.FolderExists("\\" & strIP & "\c$\users\" & strUserName & "\.nx") Then
'wShell.popup "nx",,"Error", 48
'destFolder = "\\booger\home\bhoneycutt\tmp"
sourceFolder = "\\" & strIP & "\c$\users\" & strUserName & "\.nx"
destFolder = "c:\users\" & strUserName & "\.nx"
CopyRemote sourceFolder, destFolder
End If
' SSH
If oFSO.FolderExists("\\" & strIP & "\c$\users\" & strUserName & "\.ssh") Then
'wShell.popup "ssh",,"Error", 48
'destFolder = "\\booger\home\bhoneycutt\tmp"
sourceFolder = "\\" & strIP & "\c$\users\" & strUserName & "\.ssh"
destFolder = "c:\users\" & strUserName & "\.ssh"
CopyRemote sourceFolder, destFolder
End If
' PST/OST
If oFSO.FolderExists("\\" & strIP & "\c$\users\" & strUserName & "\appdata\local\microsoft\outlook") Then
'wShell.popup "outlook",,"Error", 48
'destFolder = "\\booger\home\bhoneycutt\tmp"
sourceFolder = "\\" & strIP & "\c$\users\" & strUserName & "\appdata\local\microsoft\outlook"
'destFolder = "c:\users" & strUserName & "\appdata\local\microsoft\outlook"
CopyRemote sourceFolder, destFolder
End If
' Signatures
If oFSO.FolderExists("\\" & strIP & "\c$\users\" & strUserName & "\appdata\roaming\microsoft\signatures") Then
'wShell.popup "signatures",,"Error", 48
'destFolder = "\\booger\home\bhoneycutt\tmp"
sourceFolder = "\\" & strIP & "\c$\users\" & strUserName & "\appdata\roaming\microsoft\signatures"
destFolder = "c:\users\" & strUserName & "\appdata\roaming\microsoft\signatures"
CopyRemote sourceFolder, destFolder
End If
' Office Templates
If oFSO.FolderExists("\\" & strIP & "\c$\users\" & strUserName & "\appdata\roaming\microsoft\templates") Then
'wShell.popup "templates",,"Error", 48
'destFolder = "\\booger\home\bhoneycutt\tmp"
sourceFolder = "\\" & strIP & "\c$\users\" & strUserName & "\appdata\roaming\microsoft\templates"
destFolder = "c:\users\" & strUserName & "\appdata\roaming\microsoft\templates"
CopyRemote sourceFolder, destFolder
End If
' Firefox
If oFSO.FolderExists("\\" & strIP & "\c$\users\" & strUserName & "\appdata\roaming\mozilla\firefox\profiles") Then
'wShell.popup "profiles",,"Error", 48
'destFolder = "\\booger\home\bhoneycutt\tmp"
sourceFolder = "\\" & strIP & "\c$\users\" & strUserName & "\appdata\roaming\mozilla\firefox\profiles"
destFolder = "c:\users\" & strUserName & "\appdata\roaming\mozilla\firefox\profiles"
CopyRemote sourceFolder, destFolder
End If
' Chrome
If oFSO.FolderExists("\\" & strIP & "\c$\users\" & strUserName & "\appdata\local\google\chrome\user data\default") Then
'wShell.popup "profiles",,"Error", 48
'destFolder = "\\booger\home\bhoneycutt\tmp"
sourceFolder = "\\" & strIP & "\c$\users\" & strUserName & "\appdata\local\google\chrome\user data\default"
destFolder = "c:\users\" & strUserName & "\appdata\local\google\chrome\user data\default"
CopyRemote sourceFolder, destFolder
End If
End If
End Function
' Copy data from remote device to local
Sub CopyRemote(sourceFolder, destFolder)
'wShell.popup "Now copying " & sourceFolder & " to " & destFolder,,"blah", 48
Set dFolder = oShell.NameSpace(destFolder)
dFolder.CopyHere sourceFolder, FOF_CREATEPROGRESSDLG
End Sub
' Clean up
Set wShell = Nothing
Set oFSO = Nothing
</script>
</head>
<body onload="loadHTA()" bgcolor="#5174bc">
<table border="0" width="100%" height="100%">
<tr>
<td align="center" valign="middle">
<div id="results"></div>
</td>
</tr>
<tr>
<td align="center" valign="middle">
<input type="textbox" name="userName"></input><br>
<font size="-1"><b style="color: #fff">username</b></font><br>
<input type="textbox" name="ip"></input><br>
<font size="-1"><b style="color: #fff">ip address</b></font><br>
<br>
<button name="CopyData" onclick="CopyData()" accesskey="H" style="background-color: #d1dbe9; border:1px solid black;">
<b><u>C</u>opyData</b>
</button>
</td>
</tr>
</table>
</body>
</html