%SystemDrive%\ProgramData\Microsoft\Windows\Caches getting created when executing vb script

£可爱£侵袭症+ 提交于 2019-12-12 01:47:15

问题


I need to create some shortcuts in StartMenu Group on Windows 7 in this location C:\ProgramData\Microsoft\Windows\Start Menu\Programs.

I first create shortcuts on the desktop and then copy them to the location C:\ProgramData\Microsoft\Windows\Start Menu\Programs\. The shortcuts work properly from here but strange thing I see is that a folder structure is created from where I run my program, after I execute my script, the folder structure looks like this

%SystemDrive%\ProgramData\Microsoft\Windows\Caches

I am executing the vbscript from my java program using

Process p = Runtime.getRuntime().exec(cmd, env); 
result = p.waitFor();

cmd here is wscript.exe (path of temp file which is the vbscript) env is the arguments I pass to the vb script

My vbscript is as below

set WshShell = WScript.CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment("Process")
startMenu = WshShell.SpecialFolders("AllUsersStartMenu")
shortcutPath=WshShell.ExpandEnvironmentStrings("%shortcut_path%")
type=WshShell.ExpandEnvironmentStrings("%type%")
mydir = "\Programs\" & type & "\"
program_dir = startMenu & mydir



Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FolderExists(program_dir) = 0) Then
    execCommand = "C:\Windows\system32\cmd.exe /C md """ & program_dir & ""
    Set execStatus = WshShell.Exec(execCommand)
    ' command md take a time, this can be fail for .Save
    If execStatus.Status = 0 Then
        WScript.Sleep 1000
    End If
End If


Set fs1 = CreateObject("Scripting.FileSystemObject")
If (fs1.FolderExists(program_dir)) Then
    fs1.CopyFile shortcutPath,program_dir
End If
Set fs1 = Nothing

I don't have much of an idea why this is happening and it doesn't happen always. Any help to prevent this will be appreciated, I know I can delete that folder but I really don't want to do that unless that's the last resort.

Thanks

来源:https://stackoverflow.com/questions/24116126/systemdrive-programdata-microsoft-windows-caches-getting-created-when-executin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!