From 38048d381dc59d89b40ecd32b4da96e171f52cf8 Mon Sep 17 00:00:00 2001
From: dnomd343
Date: Wed, 10 Aug 2022 18:57:15 +0800
Subject: [PATCH] feat: add office commands
---
src/Basis.php | 23 +++++++++++++++++++++++
src/KmsWeb.php | 10 +++++-----
src/kmsCli.php | 16 ++++++++--------
3 files changed, 36 insertions(+), 13 deletions(-)
diff --git a/src/Basis.php b/src/Basis.php
index 389e71b..700853f 100644
--- a/src/Basis.php
+++ b/src/Basis.php
@@ -12,3 +12,26 @@ function getKeys(bool $isWinServer = false): array { // get kms keys asset
$keysAsset = json_decode(file_get_contents('../assets/kms-keys.json'), true);
return $isWinServer ? array_reverse($keysAsset['win-server']) : $keysAsset['win'];
}
+
+function officeCommand(string $version, string $key, string $host): string {
+ $command = 'if exist "%ProgramFiles%\Microsoft Office\\' . $version . '\ospp.vbs" ';
+ $command .= 'cd /d "%ProgramFiles%\Microsoft Office\\' . $version . "\"\n";
+ $command .= 'if exist "%ProgramFiles(x86)%\Microsoft Office\\' . $version . '\ospp.vbs" ';
+ $command .= 'cd /d "%ProgramFiles(x86)%\Microsoft Office\\' . $version . "\"\n";
+ $command .= "cscript ospp.vbs /inpkey:$key\n";
+ $command .= "cscript ospp.vbs /sethst:$host\n";
+ $command .= "cscript ospp.vbs /act\n";
+ return $command . "cscript ospp.vbs /dstatus\n";
+}
+
+function osppCommand(string $host): array {
+ return array(
+ '/dstatus' => ['Displays license information for installed product keys.', '显示当前已安装产品密钥的许可证信息'],
+ '/dstatusall' => ['Displays license information for all installed licenses.', '显示当前已安装的所有许可证信息'],
+ '/unpkey:XXXXX' => ['Uninstalls an product key with the last five digits of it.', '卸载已安装的产品密钥(最后5位)'],
+ '/inpkey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX' => ['Installs a product key with a user-provided product key.', '安装产品密钥'],
+ "/sethst:$host" => ['Sets a KMS host name with a user-provided host name.', '设置 KMS 主机名'],
+ '/remhst' => ['Removes KMS host name and sets port to default.', '删除 KMS 主机名'],
+ '/act' => ['Activates installed Office product keys.', '激活 Office'],
+ );
+}
\ No newline at end of file
diff --git a/src/KmsWeb.php b/src/KmsWeb.php
index 5cbc72c..60e4bd9 100644
--- a/src/KmsWeb.php
+++ b/src/KmsWeb.php
@@ -17,16 +17,16 @@ function showKeysWeb(array $kmsKeys, string $header): void { // show kms keys in
}
-function showHelpWeb(string $site) {
+function showHelpWeb(string $host) {
echo '';
echo '';
echo '';
echo ' KMS (Office)Windows KMS Activation
';
- echo '
slmgr /upk\n slmgr /ipk KMS_KEY\n slmgr /skms ' . $site . '\n slmgr /ato\n slmgr /dlv
';
- echo '
';
- echo 'KMS_KEY (Windows)
';
- echo 'KMS_KEY (Windows Server) slmgr /upk\n slmgr /ipk KMS_KEY\n slmgr /skms ' . $host . '\n slmgr /ato\n slmgr /dlv
';
+ echo '
KMS (Office)
';
+ echo 'KMS_KEY (Windows)
';
+ echo 'KMS_KEY (Windows Server)