作者:乔山办公网日期:
返回目录:office365
方法一:异常判断发(根据返回结果形式)// 使用地方private void buttonOk_Click(object sender, EventArgs e){if (codeboolisExcelInstalled()){MessageBox.Show("本机已安装e799bee5baa6e58685e5aeb9336Excel文件");}else{MessageBox.Show("当前系统没有发现可执行的Excel文件, 如需使用Excel功能请先安装office 2003", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);}}//判断本机是否安装Excel文件方法private bool codeboolisExcelInstalled(){Type type = Type.GetTypeFromProgID("Excel.Application");return type != null;}方法二:注册表检查发判断注册表里有没有SOFTWARE\\Microsoft\\Office\\12.0\\Word\\InstallRoot\\Excel.exe 其中12.0 11.0需要同时判断,因为11.0是office 2003 12.0是office 2007// 使用地方private void buttonOk_Click(object sender, EventArgs e){if (ExistsRegedit()){MessageBox.Show("本机已安装Excel文件");}else{MessageBox.Show("当前系统没有发现可执行的Excel文件, 如需使用Excel功能请先安装office 2003", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);}}/// <summary/// Self_Variable:查询注册表某个键值是否存在/// </summary/// <returns</returnspublic bool ExistsRegedit(){bool ifused = false;RegistryKey rk = Registry.LocalMachine;RegistryKey akey = rk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\11.0\\Word\\InstallRoot\\");RegistryKey akeytwo = rk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\12.0\\Word\\InstallRoot\\");//检查本机是否安装Office2003if (akey != null){string file03 = akey.GetValue("Path").ToString();if (File.Exists(file03 + "Excel.exe")){ifused = true;}}//检查本机是否安装Office2007if (akeytwo != null){string file07 = akeytwo.GetValue("Path").ToString();if (File.Exists(file07 + "Excel.exe")){ifused = true;}}return ifused;}提示: 方法一:本人觉得方法一比较简单,方法一已经测试过。方法二:是遍历注册表的方法,比较麻烦,上面的例子已经经过测试,如问题,查看注册表,在进行适当的内容调整(一般没问题)
$Msg = Add-Type -memberDefinition @"
[DllImport("User32")]
public static extern int MessageBox(long hWnd,string lpText,string lpCaption,int uType);
"@ -passthru -name msg
$p=$MyInvocation.MyCommand.path
function MsgBox($text){
$Msg::MessageBox(0,$text,$p,64)
}
$f=dir -r 'hkcu:\firefox'|Select-Object -First 1 -Property Name
if($f){
'已安装知'
Exit #退出程序
}else{
'未安装'
MsgBox '正在为您安装firefox中...'
#这里写安装程序路道径,去掉#即可专,比如d:\firefox.exe
}
保存属为ps1类型文件
生成到EXCEL里的不会,但是可以生成CSV文件
自己7a686964616fe59b9ee7ad94337建一个VBS文件,把下面的代码扔进去。
可以自己制定路径,生成C:\1.csv文件。
dim SF,sE,tF
dim fs,oF,sT
sub getFd(fd)
wrtf fd
for each tmpFd in fd.subfolders
getFd tmpFd
next
end sub
sub wrtF(fd)
for each tmpfile in fd.files
sE.write tmpfile.name & "," & tmpfile.size & vbcrlf
next
end sub
sF = InputBox("input your path")
set fs = CreateObject("Scripting.FileSystemObject")
set oF = fs.GetFolder(sF)
tF="C:\1.csv"
if fs.FileExists(tF) then
fs.DeleteFile tF
end if
set sE = fs.OpenTextFile (tF, 8, True)
sE.write "name,size" & vbcrlf
getFd oF
sE.close
msgbox "done!"
可以。
vbs可以看看有没有excel.application
bat可以用assoc .xls看看文件关联。